1
我有一個JSP頁面,它以我在執行spring安全性之前登錄的方式從我的accout對象中獲取用戶信息。我希望我的按鈕在用戶登錄時顯示我在div中的內容。我之前正在使用會話,但現在我正在使用Spring Security,它認爲它未登錄。我搜索了Google和Stack以嘗試查找我的問題的答案,但我不斷提出空白。這是我在JSP中所擁有的。Spring Security獲得登錄價值
<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>
<% } %>
按鈕的符號應該改變的聯繫,但它不是。
在此先感謝。
我對於如何實際做到這一點還有點困惑。我現在在頁面上添加了標籤庫,但是如何才能正常工作還不清楚。 – welfle18 2013-03-15 13:20:53
嘗試在單獨的標籤中包裝原始'<% if %>'的兩個分支:第一個使用'access =「isAnonymous()」'第二個使用'access =「isAuthenticated()」'。如果仍然無法解決問題,請使用新版本的JSP和問題的確切描述來更新您的問題,否則它不會很容易爲您提供幫助。 –
zagyi
2013-03-15 13:38:28
謝謝你,我現在工作很好!謝謝您的幫助。 – welfle18 2013-03-15 14:02:46