execAndWait拦截器出现问题,SESSION丢失
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现 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().
在 struts.xml 中提及,因为
它在我的机器上运行良好
mention in struts.xml as
it is working fine on my machine