2013-04-30 81 views
1

我有一個index.jsp頁面,它包含一個完美的消息和登錄表單,但是當用戶登錄時,我需要它留在index.jsp頁面上,只需用登出鏈接替換登錄表單就可以了。 ?一旦用戶登錄,如何將登錄表單更改爲註銷鏈接?

我知道我可以使用以下內容,但不知道如何在運行時用登錄表單替換它。

<a href="<c:url value="j_spring_security_logout" />" > Logout</a> 

登錄形式,它是在index.jsp中

<form action="<c:url value='j_spring_security_check'/>" method='post'> 
       <label for="j_username">Username</label> 
       <input type="text" name="j_username" id="j_username"/><br/> 
       <label for="j_password">Password</label> 
       <input type="password" name="j_password" id="j_password"/><br/> 
       <input type='checkbox' name='_spring_security_remember_me'/> Remember me<br/> 
       <input type="submit" value="Login"/> 
       <input type="reset" value="Reset"/> 
      </form> 
+0

你有一個活的網站或那個的jsfiddle我們可以看看?您添加的代碼並不能真正幫助您找到解決方案。 – EnigmaRM 2013-04-30 04:41:19

+0

不,它在我的本地主機上工作你需要知道我可以上傳代碼,index.jsp頁面只是一個消息和上面的表格,我只需要用戶登錄時用註銷鏈接替換表單。 – J888 2013-04-30 04:44:09

+1

猜猜我不熟悉彈簧安全。雖然在SO上發現了類似的帖子。可以幫助你一點:http://stackoverflow.com/questions/3139718/spring-security-changing-spring-security-login-form?rq=1 – EnigmaRM 2013-04-30 04:55:55

回答

3

您可以一起選擇使用Spring Security taglibSpEL expressions

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 

<sec:authorize access="isAuthenticated()"> 
    <a href="<c:url value="j_spring_security_logout" />" > Logout</a> 
</sec:authorize> 

<sec:authorize access="isAnonymous()"> 
    <!-- Login form goes here --> 
</sec:authorize>