如何解决 JSF 1.2 中的 ViewExpiredException

发布于 2024-12-18 12:46:34 字数 302 浏览 1 评论 0原文

我有一个使用 JSF1.2 + Richfaces 3.3.3 Final、MyFaces 1.2.7、Spring + Hibernate 的应用程序,每次清除浏览器的缓存和 cookie 并再次登录我的应用程序时,都会出现以下异常。

javax.faces.application.ViewExpiredException - /app/project/index.jsf
找不到视图标识符的已保存视图状态:/app/project/index.jsf

谁能让我知道如何解决上述异常?

I have an application using JSF1.2 + Richfaces 3.3.3 Final, MyFaces 1.2.7, Spring + Hibernate and I get the below exception everytime when I clear the cache and cookies of the browser and login again to my application.

javax.faces.application.ViewExpiredException - /app/project/index.jsf
No saved view state could be found for the view identifier: /app/project/index.jsf

Can anyone let me know how to solve above exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2024-12-25 12:46:34

您可以通过将状态保存方法设置为 client 而不是 server 来解决此问题,以便将视图存储(当然以序列化形式)在 POST 的隐藏输入字段中表单中,而不是在服务器端的会话中(这又由 JSESSIONID cookie 引用;因此​​,当您删除会话 cookie 或会话过期时,所有视图基本上都会丢失)。您可以通过将以下上下文参数添加到 web.xml 中来做到这一点:

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

如果由于某种原因上述内容不是一个选项,那么您可以做的最好的事情就是将其作为错误页面温和地处理web.xml 如下:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/errors/sessionexpired.jsf</location>
</error-page>

这并不能解决异常,但它至少为您提供了在错误页面中告诉最终用户有关问题以及应采取哪些操作的机会最终用户必须采取。您甚至可以让错误页面指向登录页面,并有条件地呈现一些有关最终用户为何再次面对登录页面的消息。

另请参阅:

You can solve it by setting the state saving method to client instead of server so that views are stored (in serialized form, of course) in a hidden input field of the POST form, instead of in the session in the server side (which is in turn to be referenced by JSESSIONID cookie; so all views will basically get lost when you delete the session cookie or when the session expires). You can do that by adding the following context parameter to the web.xml:

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

If the above is not an option for some reason, then best what you could do is to handle it gently as an error page in web.xml as follows:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/errors/sessionexpired.jsf</location>
</error-page>

This does not solve the exception, but it at least offers you the opportunity to tell in the error page the enduser about the problem and what actions the enduser has to take. You could even let the error page point to the login page and conditionally render some message about why the enduser is facing the login page again.

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文