gpt4 book ai didi

java - Spring Security 获取登录值

转载 作者:太空宇宙 更新时间:2023-11-04 07:45:11 25 4
gpt4 key购买 nike

我有一个 JSP 页面,它从 Java 中的 accout 对象获取用户信息,就像我在实现 Spring Security 之前进行登录一样。我希望我的按钮在用户登录时显示我在 div 中的内容。我以前使用过 session ,但现在我使用 Spring Security,它认为它没有登录。我搜索了 google 和 Stack,试图找到我的问题的答案,但我不断出现空白。这是我的 JSP 中的内容。

<div id="topRightMenu" class="f-right">
<% if( session.getAttribute("auth") == null
|| session.getAttribute("auth").toString() == "false"
|| session.getAttribute("Account") == null) { %>


<div id="login-form">
<form action="/<c:url value='j_spring_security_check' />" method="post" id="loginForm">
Username: <input class="text small" type="text" name="j_username" value="" /><br/>
Password: <input class="text small" type="password" name="j_password" value="" /><br/>
<label class="uiButton uiButtonLarge btnLogin">
<input type="submit" name="btnLogin" value="login" />
</label>
</form>
</div>

<button class="f-right" id="loginButton">Sign In</button>

<% } else { %>
<ul class="noMarkers grid">
<li><a href="/account/edit/" title="Click to View Account Information">Account</a></li>
<li><a href="/profile/<%= Acc.getAccountID() %>" title="Click to View Your Profile">Profile</a></li>
<li><a href="/help" title="Click to Get Help">Help</a></li>
<li><a href="/account/logout" title="Log Out">Log Out</a></li>
</ul>
<% } %>

登录按钮应该更改为链接,但事实并非如此。
提前致谢。

最佳答案

尝试使用taglib provided by Spring Security 。特别是,您可以使用 <sec:authorize>标签:

<sec:authorize access="isAuthenticated()">
....
</sec:authorize>

来自其文档:

A tag which outputs the body of the tag if the configured access expression evaluates to true for the currently authenticated principal.

有关可在 access 中使用的功能的概述上面的表达式,检查 this section引用文档。

关于java - Spring Security 获取登录值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15419938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com