我一直在尝试为JSF 2.2设置OCPsoft的重写http://ocpsoft.org/rewrite/examples/。
我的设置:
我的pom.xml包含以下两个依赖项
<!-- for JSF 2.x -->
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>2.0.12.Final</version>
</dependency>
我在WEB-INF文件夹中放置了一个pretty-config.xml
<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="test">
<pattern value="/test" />
<view-id value="/home/index.jsf" />
</url-mapping>
</pretty-config>
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>myproject</display-name>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.CDN_RESOURCE_HANDLER_URLS</param-name>
<param-value>primefaces:jquery/jquery.js=http://code.jquery.com/jquery-1.11.0.min.js</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>State saving method: "client" or "server" (= default)
See JSF Specification 2.5.2. Zur Produktion wieder auf server schalten. HTTP
GET Request zusammen mit 'client'
führen zum Verlust des STATE</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<description>Next step - disable compression of state in server</description>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>If true, rendered HTML code will be formatted, so that
it is "human readable". i.e. additional line separators and whitespace will
be written, that do not influence
the HTML code. Default: "true"</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>Very important, too, is to disable the serialization
of state, serialization and deserialization of the component tree is a
major
performance hit
</description>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<!-- Verschlüsselung des Viewstates -->
<context-param>
<param-name>org.apache.myfaces.secret</param-name>
<param-value>NzY1NDMyMTA=</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.numberOfViewsInSession</param-name>
<param-value>3</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.numberOfLogicalViews</param-name>
<param-value>10</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error/404.jsf</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/home/index.jsf</location>
</error-page>
<filter>
<filter-name>adminPinFilter</filter-name>
<filter-class>com.myproject.filters.AdminPinFilter</filter-class>
</filter>
<filter>
<filter-name>facesRedirectFilter</filter-name>
<filter-class>com.myproject.filters.FacesRedirectFilter</filter-class>
<init-param>
<description>Auf diese Extension soll nicht direkt zugegriffen
werden
(z.B. .xhtml)</description>
<param-name>forbiddenExtension</param-name>
<param-value>.xhtml</param-value>
</init-param>
<init-param>
<description>Auf diese Extension soll umgeleitet werden (z.B. .jsf)</description>
<param-name>redirectExtension</param-name>
<param-value>.jsf</param-value>
</init-param>
</filter>
<filter>
<filter-name>directGetFilter</filter-name>
<filter-class>com.myproject.filters.DirectGetFilter</filter-class>
</filter>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>com.myproject.filters.SessionFilter</filter-class>
</filter>
<filter>
<filter-name>authFilter</filter-name>
<filter-class>com.myproject.filters.AuthFilter</filter-class>
</filter>
<filter>
<filter-name>offerFilter</filter-name>
<filter-class>com.myproject.filters.OfferFilter</filter-class>
</filter>
<filter>
<filter-name>adminAuthFilter</filter-name>
<filter-class>com.myproject.filters.AdminAuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>adminPinFilter</filter-name>
<url-pattern>/adminPin/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>facesRedirectFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>authFilter</filter-name>
<url-pattern>/profile/*</url-pattern>
<url-pattern>/conversation/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>adminAuthFilter</filter-name>
<url-pattern>/admin/panel/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>offerFilter</filter-name>
<url-pattern>/offer/view/*</url-pattern>
</filter-mapping>
<session-config>
<!-- Disables URL-based sessions (no more 'jsessionid' in the URL using
Tomcat) -->
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<listener>
<listener-class>com.myproject.system.ContextFinalizer</listener-class>
</listener>
</web-app>
但是,如果我导航到/ test,我只会收到404错误。
我错过了什么吗?
答案 0 :(得分:0)
您的Web应用程序中是否有一个名为&#34; /home/index.xhtml"的文件; (或者那种效果)?如果可能,请发布您的web.xml。谢谢!
此外,您的web.xml中似乎定义了很多过滤器,但您没有定义重写过滤器。这个应该没问题,但是,值得手动添加过滤器并查看会发生什么。重写过滤器应该是web.xml中的第一个过滤器:
<listener>
<listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
</listener>
<listener>
<listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
</listener>
<filter>
<filter-name>OCPsoft Rewrite Filter</filter-name>
<filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>OCPsoft Rewrite Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ASYNC</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
答案 1 :(得分:0)
现在一切正常。我从web.xml中删除了默认的servlet。
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>