在jsf中配置错误页面时出错? [英] Error in configure to error page in jsf?
问题描述
在我的项目中,当我的代码中出现特定错误时,我必须显示错误页面。
我在header.xhtml页面中添加了以下脚本。此页面被添加到每个页面。因此,每当出现错误时,我想显示错误页面。
In my project I have to display a error page when specific errors occurs in my code.
I have added the following script in my header.xhtml page.This page is added to each and every page.So whenever error occurs I want to display error page.
<script type="text/javascript">
A4J.AJAX.onExpired = function(loc, expiredMsg) {
window.location = "../facelets/error/invalidSessionLogin.jsf";
};
A4J.AJAX.onError = function(req, status, message) {
window.location = "../facelets/error/ajaxError.jsf";
};
</script>
但这不起作用。
我还配置500,404错误在web.xml中。代码如下。
but this is not working..
And I also configure for 500,404 error in web.xml.The code is as follows.
<context-param>
<description>Use this to suppress Facelets error page</description>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>false</param-value>
</context-param>
<error-page>
<error-code>500</error-code>
<location>/facelets/error/internalErrorHome.jsf</location>
</error-page>
<!-- if required page not available -->
<error-page>
<error-code>404</error-code>
<location>/facelets/error/pageNotFoundErrorHome.jsf</location>
</error-page>
但这会给我以下错误。
11:41:30,618 ERROR [[localhost]] Exception Processing ErrorPage[errorCode=404, location=/facelets/error/pageNotFoundErrorHome.jsf]
com.sun.faces.context.FacesFileNotFoundException: /facelets/error/pageNotFoundErrorHome.xhtml Not Found in ExternalContext as a Resource
我不喜欢我不知道我哪里错了..
我不知道在ExternalContext中找不到的错误作为资源
I don't know where I am going to wrong.. I don't get it the error Not Found in ExternalContext as a Resource
推荐答案
-
您应该测试您提到的路径是否可访问,如果路径不起作用,请先修复路径。
You should test whether the path you have mentioned is reachable or not, and firstly fix the paths if they are not working.
为什么不为这些错误代码创建导航案例,然后设置相应的URL,而不是使用相对路径。
Why don't you create a navigation case for these error codes and then instead of using relative paths, set the appropriate urls.
window.location =$ {request.contextpath} / error / 404;
window.location = "${request.contextpath}/error/404";
例如:
mywebapp
|
|---WEB-INF
|
|---error
| |
| |---404.xhtml
(and so on)
In web.xml:
In web.xml:
<error-page>
<error-code>404</error-code>
<location>/error/404.xhtml</location>
</error-page>
并且类似于500个错误代码。
and similarily for 500 error-code.
这篇关于在jsf中配置错误页面时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!