【问题标题】:spring security : logout does not work when having long relative pathspring security:当相对路径较长时注销不起作用
【发布时间】:2013-04-15 07:31:29
【问题描述】:

在我的 Spring Security 应用程序中,我的注销按钮放置了以下代码

<li><a href="<c:url value="j_spring_security_logout"/>">Log out</a></li>

现在当我的 URL 是http://localhost:8080/servletname 时,注销工作正常。

即使是http://localhost:8080/servletname/abc,它也能正常工作。

但是当 URL 是 http://localhost:8080/servletname/abc/xyz 时,当我单击注销按钮时,我会得到一个 404 页面,因为页面被重定向到 http://localhost:8080/servletname/abc/j_spring_security_logout

我该如何解决这个问题?

【问题讨论】:

    标签: java spring jsp spring-security jstl


    【解决方案1】:

    ">退出link特别是部分:

    Given a base URL and a relative URL (that does not begin with a slash), a full URL is derived as follows:
    
    If the base URL ends with a slash the full URL is derived by appending the relative URL to the base URL. For example, if the base URL is http://nosite.com/dir1/dir2/ and the relative URL is gee.html, the derived URL is http://nosite.com/dir1/dir2/gee.html.
    If the base URL doesn't end with a slash, the last piece of the base URL is considered a resource, so the full URL is derived by appending the relative URL to the parent of the base URL. For example, if the base URL is http://nosite.com/dir1/dir2 and the relative URL is gee.html, the derived URL is http://nosite.com/dir1/gee.html 
    

    您使用的是相对路径,请在 url 开头使用“/”使其成为绝对路径:

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

    【讨论】:

    • 它不起作用..它被重定向到localhost:8080/j_spring_security_logout
    • 我觉得应该是&lt;a href="&lt;c:url value="/j_spring_security_logout"/&gt;"&gt;Log out&lt;/a&gt;
    • @Dani: 完美 :) 谢谢 :)
    • 我很高兴能帮上忙……还有@Jakub,你欠我一个;)
    猜你喜欢
    • 2011-10-05
    • 2013-05-24
    • 1970-01-01
    • 2011-08-20
    • 2013-02-15
    • 1970-01-01
    • 2014-05-21
    • 2016-09-30
    • 2014-09-04
    相关资源
    最近更新 更多