我正在尝试尽可能简单地处理“ fork ”JSF2 应用程序中的错误处理,该应用程序具有用于移动和桌面的单独模板和 XHTML 页面路径。
主要的 servlet 映射(可能需要修改)目前看起来像这样
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>/javax.faces.resource/*</url-pattern>
</servlet-mapping>
在我的情况下,这适用于处理桌面错误:
<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>
但是考虑到 fork 的页面和模板集,我也想拥有
<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>
有没有办法直接在
web.xml
中执行此操作? ,要么使用与上下文根无关的路径,要么将一些配置嵌套在定义不同场景中使用的路径的 block 中?或使用 faces-config.xml
并创建可以与确切的 XHTML 文件位置匹配的自定义结果?
最佳答案
好吧,我没有得到回应(而且我真的不认为我会)。对于它的值(value),这就是我为获得预期结果所做的事情。
404.jsp
页 404.xhtml
为了清楚和简洁String pageRoot = MobileChecker.isMobile( request ) ? "mpages" : "webpages";
if(!response.isCommitted()) {
response.sendRedirect(request.getContextPath() + "/faces/" + pageRoot + "/404.xhtml");
}
“
MobileChecker
”部分是我们代码库的一个不幸的旧部分,但尽一切努力检测相关设备应被视为“移动”(UA 嗅探可以是其中的一部分,但功能检测从客户可能会更好)。我们已经在服务器级别进行了此设置,因此对应用根目录的请求已经重定向到 /webpages
。或 /mpages
路径,因此。到目前为止,这种方法似乎普遍有效。
关于jsf - 在两个不同的路径上配置相同的错误页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51449867/