javax.faces.application.ViewExpiredException 看似被忽略

发布于 2024-10-12 04:08:15 字数 4658 浏览 5 评论 0原文

我已将以下内容放入 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.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 中的最后一个过滤器条目)和一个带有 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)

我猜这是标准错误。

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>

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)

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.

Thanks

EDIT

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>

(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!

EDIT 2

Error from the 500 is:

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.

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

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

发布评论

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

评论(2

我们的影子 2024-10-19 04:08:15

这是因为 ViewExpiredException - 与其他所有 FacesException 一样 - 隐藏在 ServletException 中。该页面用于在声明的错误页面中查找匹配项。最接近的匹配是 java.lang.Throwable,因此会显示相关的错误页面。

如果没有找到匹配项,则 ServletException 的根本原因将被解包,并且将使用解包的异常第二次遍历声明的错误页面。如果删除 java.lang.Throwable 条目,您将发现这可以工作。

如果您想保留 java.lang.Throwable,那么您能做的最好的事情就是创建一个 Filter,它可以从ServletException 并重新抛出它。

另请参阅:

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.

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.

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.

See also:

总以为 2024-10-19 04:08:15

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

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.

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