java javax.faces.application.ViewExpiredException 貌似被忽略了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4716030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:41:04  来源:igfitidea点击:

javax.faces.application.ViewExpiredException seemingly ignored

javajsfviewexpiredexception

提问by volvox

I've put the following into my web.xml:

我已将以下内容放入我的 web.xml 中:

    <error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/expiredIndex.jsf</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.jsf</location>
</error-page>
<session-config>
    <session-timeout>1</session-timeout>
</session-config>

When I start my app, and wait for 1 minute, if I then attempt to interact with it (JSF 1.2, h:commandButton) I get the error

当我启动我的应用程序并等待 1 分钟时,如果我尝试与之交互(JSF 1.2,h:commandButton),我会收到错误消息

 SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.application.ViewExpiredException: viewId:/index.jsf - View /index.jsf could not be restored.
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:185)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:103)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

Can someone tell me why it is the javax.faces.application.ViewExpiredExceptionis not being picked up? I'm looking for the most basic expiry setup possible and surely that's all that is necessary in the web descriptor.

有人能告诉我为什么它javax.faces.application.ViewExpiredException没有被捡起来吗?我正在寻找可能的最基本的到期设置,当然这就是 Web 描述符中所需的全部内容。

Thanks

谢谢

EDIT

编辑

I now have in my web.xml the following:

我现在在我的 web.xml 中有以下内容:

<filter>
    <filter-name>Error</filter-name>
    <filter-class>myClient.ErrorFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>Error</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

    <error-page>
        <exception-type>javax.servlet.ViewExpiredException</exception-type>
        <location>/expiredIndex.jsf</location>
    </error-page>

(these entries are the last filter entries in the web.xml) and a new filter with the doFilter method as described in thispost. What should be happening now is the rootCauseshould unwrap the ViewExpiredException which should thus redirect the user to my expiredIndexpage when the servlet session times out. Instead I get a 500. I can't see what else to I need to do the correct redirect in this situation. Help!

(这些项是在web.xml最后过滤器的项)中,用如上述doFilter方法一个新的过滤柱。现在应该发生的是rootCause应该解开 ViewExpiredException 这应该expiredIndex在 servlet 会话超时时将用户重定向到我的页面。相反,我得到了 500。我看不出在这种情况下我还需要做什么才能正确重定向。帮助!

EDIT 2

编辑 2

Error from the 500 is:

500 的错误是:

javax.faces.application.ViewExpiredException: viewId:/index.jsf - View /index.jsf could not be restored.
    com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:185)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:103)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    prismClient.ErrorFilter.doFilter(Unknown Source)

which I guess is the standard one.

我想这是标准的。

回答by BalusC

This is because the ViewExpiredException-as every other FacesException- is under the covers been wrapped in a ServletException. This one is been used to find matches in the declared error pages. The closest match is java.lang.Throwableand thus the associated error page is been shown.

这是因为ViewExpiredException- 和其他所有东西一样FacesException- 在封面下被包裹在ServletException. 这个用于在声明的错误页面中查找匹配项。最接近的匹配是java.lang.Throwable,因此显示了相关的错误页面。

If no match would have been found, then the root cause of the ServletExceptionwould have been unwrapped and a second pass through the declared error pages will be made with the unwrapped exception. If you remove the java.lang.Throwableentry, you'll see that this will work.

如果未找到匹配项,则 的根本原因ServletException将被解包,并且将使用解包异常进行第二次通过声明的错误页面。如果您删除该java.lang.Throwable条目,您将看到这将起作用。

If you want to keep the java.lang.Throwable, then best what you can do is to create a Filterwhich unwraps any FacesExceptionfrom the ServletExceptionand rethrows it.

如果你想保留java.lang.Throwable的话,最好你可以做的是建立一个Filter其解开任何FacesException来自ServletException和重新抛出它。

See also:

也可以看看:

回答by user6745578

Please see the blog posted on similar issue here: it's less cumbersome and quite effective. Be sure to include your "view-handler" tags within the "application" tags, doing this worked for me, cheers.

请在此处查看有关类似问题的博客:它不那么麻烦且非常有效。确保在“应用程序”标签中包含您的“视图处理程序”标签,这样做对我有用,干杯。