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

时间:2010-06-21 06:18:27

标签: interceptor

我正在使用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文件中的execute方法

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

如果没有使用拦截器,它会正确地给出会话..但是,如果使用了拦截器代码,那么它会抛出NULL指针异常..

请告诉我如何解决这个问题..

2 个答案:

答案 0 :(得分:2)

实现SessionAware

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

重要说明:由于操作将在单独的线程中运行,因此您无法使用ActionContext,因为它是ThreadLocal。这意味着如果您需要访问(例如)会话数据,则需要实现SessionAware而不是调用ActionContext.getSesion()。

答案 1 :(得分:0)

在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>

它在我的机器上正常工作

相关问题