How to handle session expiration and ViewExpiredException in JSF 2?

后端 未结 1 1840
忘了有多久
忘了有多久 2020-11-28 02:40

Consider the following scenario. I am clicking the submit button of a JSF form, after the session has timed out(expired). The browser displays some exception message:

相关标签:
1条回答
  • 2020-11-28 02:43

    To handle the exception whenever the user invokes a synchronous POST request on a page while the HTTP session has been expired and the JSF view state saving method is set to server, add an <error-page> to the web.xml which catches the JSF ViewExpiredException and shows the home page.

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/home.xhtml</location>
    </error-page>
    

    To handle the exception on asynchronous (ajax) requests as well, you need to implement a custom ExceptionHandler as answered in Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

    See also:

    • javax.faces.application.ViewExpiredException: View could not be restored
    0 讨论(0)
提交回复
热议问题