2014-12-06 29 views
0

我正在研究基于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标签,很烦人!

+0

您可以包括您的PrettyFaces配置吗? – chkal 2014-12-08 09:20:58

+0

@chkal没问题。 – Aayush 2014-12-08 09:57:53

+0

您是否将http错误映射到web.xml中的特定页面? – chkal 2014-12-08 13:21:59

回答

0

我有同样的问题,你的,但是当我添加“/ WEB-INF”到view-id值它的工作!即:

... 
    <url-mapping id="home"> 
      <pattern value="/home/" /> 
      <view-id value="/WEB-INF/index.jsf" /> 
    </url-mapping> 
    ... 

它的工作原理,但我并没有被这个解决方案说服,我试图去调查

+0

啊我明白了。就我而言,我不知道发生了什么,但最糟糕的部分是Google AppEngine不让我为404错误代码提供自定义错误页面。所以,我最终转向使用相同代码和项目的VPS设置,一切正常! – Aayush 2015-02-02 21:47:07