没有重定向到web.xml中指定的页面 [英] no redirect to page specified in web.xml

查看:166
本文介绍了没有重定向到web.xml中指定的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSF应用程序中,每当发生异常时,它都应显示一个JSF页面,该页面旨在向用户显示发生了错误,但是没有发生这种情况,这是个大问题.

in my JSF application whenever an exception occurs, it should display a JSF page, which I designed to show the user that an error occurred, but no such thing happens, that's the big problem.

我的web.xml的一部分

Part of my web.xml

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/faces/error.jsf</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/faces/error.jsf</location>
   </error-page>

推荐答案

在ajax请求期间发生异常时,或者在已经提交响应时发生异常时,就会发生这种情况.

That can happen when the exception occurs during an ajax request, or when the exception occurs when the response has already been committed.

ajax请求的异常需要由自定义的 ExceptionHandler . OmniFaces 有这样一个, FullAjaxExceptionHandler ,它使用标准的Servlet API错误页面机制.

Exceptions on ajax requests needs to be handled by a custom ExceptionHandler. OmniFaces has such one, the FullAjaxExceptionHandler which utilizes standard Servlet API error page mechanism.

提交响应时无法处理异常,因为响应的一部分已经发送到客户端,这是无法返回的点.只能通过在web.xml中使用以下上下文参数增加响应缓冲区的大小来避免这种情况:

Exceptions while the response is committed cannot be handled because a part of the response has already been sent to the client which is a point of no return. It can only be avoided by increasing the response buffer size by the following context parameter in web.xml:

<context-param>
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
    <param-value>65535</param-value>    
</context-param>

上面的示例将其设置为64KB,应该与最大页面的大小差不多.这样,直到大小达到64KB或完成时才提交响应.这样,当发生异常时,容器将能够更改对错误页面的响应.

The above example sets it to 64KB, it should be about the size of your largest page. This way the response won't be committed until the size reaches 64KB or when it's finished. This way the container will be able to change the response to the error page when an exception occurs.

无关与具体问题无关,您在此处的错误页面配置中存在重叠.异常隐式始终为状态500,并且您指向的是同一错误页面.因此,带有java.lang.Exception的错误页面是多余的.

Unrelated to the concrete problem, you've by the way an overlap in the error page configuration there. Exceptions are implicitly always status 500 and you're pointing to the same error page. So the error page one with java.lang.Exception is superflous.

这篇关于没有重定向到web.xml中指定的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆