我正在开发基于Java和JSF2.0的Web应用程序,我正在使用Google AppEngine来托管它。我正在使用PrettyFaces来修改URL。自从我开始使用PrettyFaces以来,如果有人输入了无效的URL,则会发生重定向循环,如下所示:
www.example.com
是网站 所以,如果你输入
www.example.com/invalidasdas
它会一直将index.jsp附加到无效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标签,这很烦人!
答案 0 :(得分:0)
我遇到了与你相同的问题,但是当我添加&#34; / WEB-INF&#34;查看id值它的工作原理!即:
...
<url-mapping id="home">
<pattern value="/home/" />
<view-id value="/WEB-INF/index.jsf" />
</url-mapping>
...
它有效,但我不相信这个解决方案,我正在尝试调查它