会话通过web.xml到期后,将用户重定向到错误页面(xhtml)

时间:2013-10-23 07:06:00

标签: jsf-2 glassfish cdi web.xml weld

我的环境是:NetBeans7.2.1,GlassFish3.1,JSF2和Weld 1.1.0。

当通话时间到期时,我想重定向到error.xhtml页面。 在web.xml里面我添加了这段代码:

<error-page>
    <exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>
    <location>/error.xhtml</location>
</error-page>

但后来我得到了这个异常错误:

WARNING: org.apache.catalina.core.StandardHostValve@365f4aa6: Exception Processing ErrorPage[exceptionType=org.jboss.weld.context.NonexistentConversationException, location=/error.xhtml]
javax.servlet.ServletException: WELD-000321 No conversation found to restore for id 1

当我使用名为ErrorHandler的Servlet侦听器在web.xml中使用此代码捕获此异常时:

<error-page>
    <exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>
    <location>/ErrorHandler</location>
</error-page>

它工作正常,我从那里重定向到error.xhtml。

我需要该位置直接使用web.xml(而不是servlet)。

我尝试将xhtml页面更改为html,但它仍无效,但异常情况不同:

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces     Servlet threw exception
 org.jboss.weld.context.NonexistentConversationException: WELD-000321 No conversation found to restore for id 1

我还尝试将位置的根目录更改为/faces/error.xhtml,但仍然无效。

可能是什么问题?如何从web.xml重定向到页面?

提前感谢。

1 个答案:

答案 0 :(得分:0)

您需要在网址中添加nocid参数,因为您的错误原因是CDI正在向error.xhtml页面发送不存在的会话ID。所以试试

<error-page>
    <exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>
    <location>/error.xhtml?nocid=true</location>
</error-page>

更多信息here