简体   繁体   中英

no redirect to page specified in web.xml

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.

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>

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

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.

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>

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.


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM