简体   繁体   中英

Redirection by Pretty Faces

I have come across a problem in which Pretty Faces will result in an infinite loop, ended by my Browser: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

The exact cause of the problem

File structure

在此处输入图片说明

pretty-config.xml fragment

<url-mapping id="login">
    <pattern value="/login" />
    <view-id value="/login/login.xhtml" />
</url-mapping>

<url-mapping id="register">
    <pattern value="/register" />
    <view-id value="/login/register.xhtml" />
</url-mapping>

Description

Navigation to localhost:8080/register will result in my webpage. Navigation to localhost:8080/login will result in the described loop, note that the navigation will result in redirection to localhost:8080/login/ <-- a trailing slash.

My guess, localhost:8080/login is a request for the folder login . But I do not know how to fix it, so my request for localhost:8080/login will result in the webpage.

Thanks in advance.

I also had this problem in the past. The problem is your Servlet container. If you are requesting an URL like /login , you container checks, if there is a directory in you web app that is named login . If so, it redirects you to /login/ , because the container thinks that you want to reach this directory. If there are also rewrite rules that remove trailing slashes, you will see a behavior like this.

I know that this is strange, but some guy on the tomcat user list wrote, that this behavior is according to the spec.

So the only solution would be to either change /login to /login/ in your mapping or to rename the login folder in your webapp.

My only guess is that your FacesServlet is mapped to *.xhtml so when a request is processed, first your pretty filter forwards it to your FacesServlet, but, because your xhtml files are in the path, the forward is then again processed by your pretty filter ad infinitum.

To solve it, put your views inside the WEB-INF folder and in your pretty.config.xml put something like this:

 <url-mapping id="login">
    <pattern value="/login/" />
    <view-id value="/WEB-INF/views/login.xhtml" />
 </url-mapping>

This way the path intercepted by the filter is not the same of your servlet because clients can request resources in the WEB-INF folder

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