简体   繁体   中英

spring security : logout does not work when having long relative path

In my spring security app, I have my logout button placed with the following code

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

Now when my URL is http://localhost:8080/servletname , logout works fine.

Even when it is http://localhost:8080/servletname/abc it works fine.

But when the URL is http://localhost:8080/servletname/abc/xyz , when I click the logout button, I get a 404 page as the page is redirected to http://localhost:8080/servletname/abc/j_spring_security_logout .

How can I resolve this?

">Log outsee link especially part:

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 

You're using relative path, make it absolute by using "/" at beginning of url:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM