看似忽略了javax.faces.application.ViewExpiredException [英] javax.faces.application.ViewExpiredException seemingly ignored
问题描述
我已将以下内容放入我的web.xml:
I've put the following into my 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>
当我启动应用程序并等待1分钟时,如果我尝试与之交互( JSF 1.2, h:commandButton
)我收到错误
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
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)
有人可以告诉我为什么它是 javax.faces.application.ViewExpiredException
未被提取?我正在寻找可能的最基本的到期设置,当然这也是网页描述符中所需要的。
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.
谢谢
编辑
我现在在我的web.xml中有以下内容:
I now have in my web.xml the following:
<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>
(这些条目是web.xml中的最后一个过滤条目)和带有doFilter的新过滤器此发布。现在应该发生的是 rootCause
应该打开ViewExpiredException,因此应该将用户重定向到我的 expiredIndex
页面。 servlet会话超时。相反,我得到500.在这种情况下,我无法看到我还需要做哪些正确的重定向。帮助!
(these entries are the last filter entries in the web.xml) and a new filter with the doFilter method as described in this post. 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!
编辑2
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)
我猜是标准的。
推荐答案
这是因为 ViewExpiredException
- 每隔一个 FacesException
- 是封闭的包含在 ServletException
中。这个用于在声明的错误页面中查找匹配项。最接近的匹配是 java.lang.Throwable
,因此显示了相关的错误页面。
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.
如果不匹配如果已经找到,那么 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.
如果你想要保留 java.lang.Throwable
,那么你最好的办法是创建一个过滤器
,它可以解包任何来自 ServletException
的 FacesException
并重新抛出它。
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.
- Issue with JSF
ViewExpiredException
and multiple error page definitions
这篇关于看似忽略了javax.faces.application.ViewExpiredException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!