有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

无效URL上的java PrettyFaces重定向循环

我正在开发一个基于Java和JSF2的web应用程序。0,我正在使用Google AppEngine来托管它。我正在使用PrettyFaces来修改URL。自从我开始使用PrettyFaces以来,如果有人输入了无效的URL,就会出现如下重定向循环:

www.example.com 

是网站吗 所以如果你进去

www.example.com/invalidasdas 

它不断追加索引。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>

这是我的网站。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标签,这很烦人


共 (1) 个答案

  1. # 1 楼答案

    我的问题与您的问题相同,但当我添加“/WEB-INF”以查看id值时,它会起作用!即:

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

    它是有效的,但我不相信这个解决方案,我正在尝试调查它