我有一个JSP页面,它用Java从我的帐户对象中获取用户信息,就像我在实现spring安全性之前所做的那样。我想让我的按钮在用户登录时显示我的div中的内容。我之前一直在使用这个会话,但现在我使用了Spring Security,它认为它没有登录。我在谷歌和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>
<% } %>登录按钮应该更改为链接,但它不是。
提前谢谢。
发布于 2013-03-15 05:08:25
尝试使用taglib provided by Spring Security。特别是,您可以使用<sec:authorize>标记:
<sec:authorize access="isAuthenticated()">
....
</sec:authorize>从它的文档中:
对于当前已验证的主体,如果配置的访问表达式的计算结果为true,则输出标记正文的标记。
有关可以在上面的access表达式中使用的函数的概述,请查看参考文档的this section。
https://stackoverflow.com/questions/15419938
复制相似问题