【问题标题】:redirect user to error page (xhtml) after conversation expired through web.xml会话通过 web.xml 过期后将用户重定向到错误页面 (xhtml)
【发布时间】:2013-11-01 08:04:57
【问题描述】:

我的环境是: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 重定向到页面?

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    您需要在 URL 中添加 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

    【讨论】:

    • 这是错误: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
    • 哇,那我不知道,这正是 nocid 参数应该防止的
    • 即使error.xhtml 不使用对话?知道是什么原因造成的吗?好像找不到页面,我不知道为什么.....
    猜你喜欢
    • 2014-06-05
    • 1970-01-01
    • 2017-06-18
    • 2017-06-19
    • 2010-10-25
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    相关资源
    最近更新 更多