【问题标题】:Error in configure to error page in jsf?配置到jsf中的错误页面时出错?
【发布时间】:2013-06-09 10:44:42
【问题描述】:

在我的项目中,当我的代码中出现特定错误时,我必须显示错误页面。
我在 header.xhtml 页面中添加了以下脚本。此页面添加到每个页面。因此,每当发生错误时,我都想显示错误页面。

<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>

但这不起作用..
而且我还在web.xml中配置了500404错误。代码如下。

 <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

我不知道我会错在哪里.. 我没有得到错误 Not Found in ExternalContext as a Resource

【问题讨论】:

    标签: java javascript jsp jsf jsf-2


    【解决方案1】:
    1. 你应该测试你提到的路径是否可达,如果路径不通,首先修复。

    2. 为什么不为这些错误代码创建一个导航案例,而不是使用相对路径,而是设置适当的 url。

      window.location = "${request.contextpath}/error/404";

    举个例子:

       mywebapp
       |
       |---WEB-INF 
       |
       |---error
       |    |
       |    |---404.xhtml
    
      (and so on)
    

    在 web.xml 中:

     <error-page>
         <error-code>404</error-code>
         <location>/error/404.xhtml</location>
     </error-page>
    

    同样适用于 500 错误代码。

    【讨论】:

    【解决方案2】:

    AFAIK 您不能在 web.xml 中将 JSF 页面注册为错误页面。相反,您必须使用 JSP。

    <error-page>
      <error-code>404</error-code>
      <location>/error404.jsp</location>
    </error-page>
    

    【讨论】:

    • 是的,您可以使用 JSF 页面
    • @tmandry:我不明白这是为什么。你能解释一下吗?我对“* .xhtml”文件作为错误页面有同样的问题。它们不起作用。
    猜你喜欢
    • 1970-01-01
    • 2012-04-22
    • 2012-03-04
    • 2012-04-18
    • 2012-10-18
    • 2021-10-07
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多