0
我想將所有404錯誤重定向到帶有漂亮面板的自定義網址。 我嘗試了很多的事情,但我無法找到合適的解決方案,以我的情況(儘管很多職位的這個)使用Prettyfaces 3.3.X和JSF 2.2重定向404錯誤
以下一些信息
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- JSF configuration
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- PrettyFaces configuration
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>
<param-value>com.lagoon.project.web</param-value>
</context-param>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Server configuration
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>404</exception-type>
<location>/page-introuvable</location>
</error-page>
</web-app>
下網頁\模塊\網站
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TODO supply a title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div>404</div>
</body>
</html>
豆
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
@RequestScoped
@URLMapping(id = "pageWebSitePageNotfound", pattern = "/page-introuvable", viewId = "/modules/website/pageNotFound.xhtml")
@ManagedBean(name = "pageWebSitePageNotfound")
public class PageWebSitePageNotfound {
}
和POM文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lagoon</groupId>
<artifactId>project</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>project</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<jsf.version>2.2.8-02</jsf.version>
<spring.version>4.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Web
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>com.ocpsoft</groupId>
<artifactId>prettyfaces-jsf2</artifactId>
<version>3.3.3</version>
</dependency>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Misc
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
當我嘗試「/頁introuvable」 JSF告訴我的網頁...但如果我嘗試「/ somethingElse」我只是有一個標準404錯誤從我的導航
我該怎麼辦?
感謝
請編輯您的[現有答案](https://stackoverflow.com/a/28726027),而不是發佈一個新的。 – 2015-02-25 18:07:06