我一直在嘗試爲JSF 2.2設置OCPsoft的Rewrite http://ocpsoft.org/rewrite/examples/。/test到/home/index.jsf的URL映射僅導致404
我的設置:
- JSF 2.2
- 的Tomcat 7
- Servlet容器3.0
- Maven項目
- URLRewrite版2.0.12
我的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>
我已經把一個漂亮的-config.xml中在我的WEB-INF文件夾
<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>
但是,如果我瀏覽到/測試,我米只會得到一個404錯誤。
有什麼我錯過了嗎?
編輯我的帖子上面,是的我在我的主目錄中有一個index.xhtml – kevcodez 2014-10-06 18:45:38
編輯我的答案,再試一次? – Lincoln 2014-10-06 22:29:00
在上面添加了過濾器和偵聽器,沒有改變。 AFAIK,在使用servlet容器3.0時,最新版本的重寫不需要額外的過濾器。 – kevcodez 2014-10-07 09:03:01