我将以下内容放入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),则会收到错误消息

 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没有被拾取吗?我正在寻找最基本的到期设置,并且肯定这是Web描述符中所需的全部。

谢谢

编辑

现在,我的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>


(这些条目是web.xml中的最后一个过滤器条目),以及一个新的过滤器,该过滤器具有this帖子中所述的doFilter方法。现在应该发生的是rootCause应该打开ViewExpiredException的包装,这样,当servlet会话超时时,应该将用户重定向到我的expiredIndex页面。取而代之的是我得到500。在这种情况下,我看不到要做正确的重定向还需要做什么。救命!

编辑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,因此显示了相关的错误页面。

如果找不到匹配项,则将解开ServletException的根本原因,并使用已解开的异常再次遍历已声明的错误页面。如果删除java.lang.Throwable条目,您将看到它将起作用。

如果要保留java.lang.Throwable,那么最好的办法是创建一个Filter,该FacesException将从ServletException中解包任何ViewExpiredException并将其重新抛出。

也可以看看:


Issue with JSF and multiple error page definitions

关于java - 似乎已忽略javax.faces.application.ViewExpiredException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4716030/

10-11 01:02