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
javax.faces.application.ViewExpiredException seemingly ignored
提问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.ViewExpiredException
is 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 rootCause
should unwrap the ViewExpiredException which should thus redirect the user to my expiredIndex
page 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.Throwable
and 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 ServletException
would 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.Throwable
entry, 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 Filter
which unwraps any FacesException
from the ServletException
and rethrows it.
如果你想保留java.lang.Throwable
的话,最好你可以做的是建立一个Filter
其解开任何FacesException
来自ServletException
和重新抛出它。