我正在研究基於Java和JSF2.0的Web應用程序,並且正在使用Google AppEngine來託管它。我正在使用PrettyFaces修改網址。自從我開始使用PrettyFaces,如果有人輸入了一個無效URL,重定向發生循環這樣的:如果你輸入PrettyFaces在無效URL上重定向循環
www.example.com/invalidasdas
它不斷追加的index.jsp到
www.example.com
是網站 所以無效URL的末尾如:
www.example.com/invalidasdas/index.jsp/index.jsp/index.jsp/index.jsp/index.jsp
我不知道如何解決這個問題。任何解決這個問題的建議都會很好。如果需要,我可以發佈我的代碼。
PrettyFaces配置:
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="home">
<pattern value="/home/" />
<view-id value="/index.jsf" />
</url-mapping>
<url-mapping id="blog">
<pattern value="/blog/" />
<view-id value="/blog.jsf" />
</url-mapping>
<url-mapping id="stockpicks">
<pattern value="/stocks/" />
<view-id value="/stockpicks.jsf" />
</url-mapping>
<url-mapping id="login">
<pattern value="/login/" />
<view-id value="/adminlogin.jsf" />
</url-mapping>
<url-mapping id="dashboard">
<pattern value="/dashboard/" />
<view-id value="/dashboard.jsf" />
</url-mapping>
<url-mapping id="error">
<pattern value="/error/" />
<view-id value="/WEB-INF/error.jsf" />
</url-mapping>
<url-mapping id="search">
<pattern value="/search/#{searchBean.type}/#{searchBean.value}"></pattern>
<view-id value="/search.jsf"/>
</url-mapping>
</pretty-config>
這是我的web.xml文件!
<?xml version="1.0" encoding="utf-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<mime-mapping>
<extension>eot</extension>
<mime-type>application/vnd.ms-fontobject</mime-type>
</mime-mapping>
<mime-mapping>
<extension>otf</extension>
<mime-type>font/opentype</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/x-font-ttf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>svg</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
<context-param>
<param-name>
javax.faces.WEBAPP_RESOURCES_DIRECTORY
</param-name>
<param-value>/WEB-INF/resources</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<error-page>
<error-code>404</error-code>
<location>/error/</location>
</error-page>
<session-config>
<session-timeout>10080</session-timeout>
<cookie-config>
<max-age>10080</max-age>
</cookie-config>
</session-config>
<filter>
<filter-name>PrettyFilter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrettyFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>filters.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/dashboard/*</url-pattern>
<url-pattern>/dashboard.jsf</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<security-constraint>
<display-name>Restrict direct access to XHTML files</display-name>
<web-resource-collection>
<web-resource-name>XHTML files</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
</web-app>
編輯:事實證明,問題是AppEngine而不是PrettyFaces。如果沒有真正查看問題,請停止編輯帖子。有人刪除了AppEngine標籤,很煩人!
您可以包括您的PrettyFaces配置嗎? – chkal 2014-12-08 09:20:58
@chkal沒問題。 – Aayush 2014-12-08 09:57:53
您是否將http錯誤映射到web.xml中的特定頁面? – chkal 2014-12-08 13:21:59