2013-04-30 85 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>