Jsf 在两个不同的路径上配置相同的错误页?
我正在尝试尽可能简单地处理“分叉”JSF2应用程序中的错误处理,该应用程序有单独的模板和移动和桌面的XHTML页面路径 当前,主servlet映射(可能需要修改)如下所示Jsf 在两个不同的路径上配置相同的错误页?,jsf,error-handling,http-status-code-404,web.xml,faces-config,Jsf,Error Handling,Http Status Code 404,Web.xml,Faces Config,我正在尝试尽可能简单地处理“分叉”JSF2应用程序中的错误处理,该应用程序有单独的模板和移动和桌面的XHTML页面路径 当前,主servlet映射(可能需要修改)如下所示 <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> <url-pattern>/javax
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>/javax.faces.resource/*</url-pattern>
</servlet-mapping>
Facesservlet
/面孔/*
/javax.faces.resource/*
在我的情况下,这可以很好地处理桌面错误:
<error-page>
<error-code>404</error-code>
<location>/faces/webpages/filenotfound.xhtml</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/faces/webpages/filenotfound.xhtml</location>
</error-page>
404
/faces/webpages/filenotfound.xhtml
java.io.FileNotFoundException
/faces/webpages/filenotfound.xhtml
但是考虑到这些分叉的页面和模板,我也希望
<error-page>
<error-code>404</error-code>
<location>/faces/mpages/filenotfound.xhtml</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/faces/mpages/filenotfound.xhtml</location>
</error-page>
404
/faces/mpages/filenotfound.xhtml
java.io.FileNotFoundException
/faces/mpages/filenotfound.xhtml
在
web.xml
中是否有直接执行此操作的方法,或者使用与上下文根无关的路径,或者将一些配置嵌套在定义在不同场景中使用的路径的块中?或者使用faces config.xml
并创建可与精确的XHTML文件位置匹配的自定义结果?嗯,我没有得到响应(而且我真的认为我不会)。值得一提的是,以下是我为获得预期结果所做的工作
404.jsp
页面404.xhtml
String pageRoot=MobileChecker.isMobile(请求)?“mpages”:“网页”;
如果(!response.isCommitted()){
sendRedirect(request.getContextPath()+“/faces/”+pageRoot+“/404.xhtml”);
}
“MobileChecker
”部分是我们代码库中不幸的老部分,但请尽一切努力检测相关设备是否应被视为“移动设备”(UA嗅探可以是其中的一部分,但从客户端传递的功能检测可能更好)。我们已经在服务器级别进行了此设置,因此对应用程序根目录的请求已经相应地重定向到/webpages
或/mpages
路径
到目前为止,这种方法似乎普遍有效