如何在JSF 2中处理会话到期和ViewExpiredException? [英] How to handle session expiration and ViewExpiredException in JSF 2?

查看:123
本文介绍了如何在JSF 2中处理会话到期和ViewExpiredException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情形. 会话超时(过期)后,我单击JSF表单的提交按钮. 浏览器显示一些异常消息:

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:

ViewExpiredException:无法还原视图上下文

ViewExpiredException: view context could not be restored

我想做的是,在会话期满后自动重定向到网站的主页.这样做的机制是什么?任何帮助将不胜感激.

What I want to do is, to automatically redirect to the homepage of the website after the session has expired. What is the mechanism to do this? Any help would be much appreciated.

推荐答案

在HTTP会话已过期且JSF视图状态保存方法设置为<时,只要用户在页面上调用同步POST请求,便要处理该异常. c0>,将<error-page>添加到web.xml,以捕获JSF ViewExpiredException 并显示主页.

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>

要同时处理异步(ajax)请求上的异常,您需要实现自定义ExceptionHandler,如

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

这篇关于如何在JSF 2中处理会话到期和ViewExpiredException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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