execAndWait拦截器出现问题,SESSION丢失

发布于 2024-09-06 05:47:27 字数 925 浏览 4 评论 0原文

我正在使用 execAndWait 拦截器,似乎会话在拦截器之后丢失了。

我的代码是 - struts-lcms.xml

...

<action name="testAction" class="com.lcms.presentation.TestAction">

   <interceptor-ref name="execAndWait"></interceptor-ref>
    <param  name="delay">3000</param>
    <param  name="delaySleepInterval">50</param>  
   <result name="wait" type="tiles">tiles.ques</result>  
   <result name="success" type="tiles">tiles.ques</result>
   <result name="diag" type="redirectAction">diagnosticAction</result>
</action>

...

如果我删除拦截器代码,那么它会将我带到问题页面(tiles.ques ) .. 但是,使用拦截器,会话为空。.

TestAction 文件中的执行方法中的这段代码,

  SessionObject sess = (SessionObject)getSession().getAttribute(LcmsConstants.SESSION_OBJECT);

如果不使用拦截器,它会正确给出会话。但是,如果使用拦截器代码,则会抛出 NULL 指针异常..

请告诉我如何克服这个问题..

I am using execAndWait interceptor and it seems the session is lost after the interceptor..

my code is - struts-lcms.xml

...

<action name="testAction" class="com.lcms.presentation.TestAction">

   <interceptor-ref name="execAndWait"></interceptor-ref>
    <param  name="delay">3000</param>
    <param  name="delaySleepInterval">50</param>  
   <result name="wait" type="tiles">tiles.ques</result>  
   <result name="success" type="tiles">tiles.ques</result>
   <result name="diag" type="redirectAction">diagnosticAction</result>
</action>

...

If I remove the interceptor code then it takes me to the question page (tiles.ques) .. However, with the interceptor the session is null..

This code in execute method in the TestAction file

  SessionObject sess = (SessionObject)getSession().getAttribute(LcmsConstants.SESSION_OBJECT);

it gives the session correctly if the interceptor is not used.. however, if the interceptor code is used then it throws NULL pointer exception..

Please tell me how to overcome this problem..

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

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

发布评论

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

评论(2

柒七 2024-09-13 05:47:27

实现 SessionAware

http://struts .apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.html

重要提示:因为该操作将在单独的线程中运行,所以您不能使用 ActionContext,因为它是一个ThreadLocal。这意味着,如果您需要访问会话数据等,则需要实现 SessionAware,而不是调用 ActionContext.getSesion()。

implements SessionAware

http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.html

Important: Because the action will be running in a seperate thread, you can't use ActionContext because it is a ThreadLocal. This means if you need to access, for example, session data, you need to implement SessionAware rather than calling ActionContext.getSesion().

原谅过去的我 2024-09-13 05:47:27

在 struts.xml 中提及,因为

<interceptor-stack name="loadingStack">
    <interceptor-ref name="completeStack" />
    <interceptor-ref name="execAndWait">
        <param name="delay">1000</param>
        <param name="delaySleepInterval">500</param>
    </interceptor-ref>
</interceptor-stack>

<interceptor-ref name="loadingStack"/>
<result name="wait">ETAX/TDS/wait.jsp</result>

它在我的机器上运行良好

mention in struts.xml as

<interceptor-stack name="loadingStack">
    <interceptor-ref name="completeStack" />
    <interceptor-ref name="execAndWait">
        <param name="delay">1000</param>
        <param name="delaySleepInterval">500</param>
    </interceptor-ref>
</interceptor-stack>

<interceptor-ref name="loadingStack"/>
<result name="wait">ETAX/TDS/wait.jsp</result>

it is working fine on my machine

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