Struts 2拦截器后无数据错误
我创建了一个全局拦截器,它将检查会话超时。
<interceptors>
<interceptor class="com.action.SessionChecker" name="sessCheck"> </interceptor>
</interceptors>
<default-interceptor-ref name="sessCheck"></default-interceptor-ref>
`
现在在 SessionChecker 中,我检查会话超时
@Override
public String intercept(ActionInvocation arg0) throws Exception {
String result;
Map<String,Object> session = arg0.getInvocationContext().getSession();
if(session.isEmpty()){
result="session_Timeout";
}
else
result=arg0.invoke();
return result;
}
在调用每个请求拦截器之前,但是它不会转到该请求的操作类,尽管我获得了与该请求相对应的页面,但没有数据。
I have created a global interceptor which will check for Session timeout.
<interceptors>
<interceptor class="com.action.SessionChecker" name="sessCheck"> </interceptor>
</interceptors>
<default-interceptor-ref name="sessCheck"></default-interceptor-ref>
`
Now it in SessionChecker I check for session timeout
@Override
public String intercept(ActionInvocation arg0) throws Exception {
String result;
Map<String,Object> session = arg0.getInvocationContext().getSession();
if(session.isEmpty()){
result="session_Timeout";
}
else
result=arg0.invoke();
return result;
}
Before every request Interceptor is getting called but, then it does not go to action class of that request and though I get corresponding page to the request there is no data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置中的以下行将会话超时拦截器配置为堆栈中唯一的拦截器,这当然不是您想要的。
相反,您需要定义一个堆栈,其中包含您想要使用的所有拦截器,并将其定义为默认值。
此外,您构建的拦截器实际上并没有检测会话已超时,而只是检测会话为空。我不确定什么正在填充您的会话,但是如果在正确填充新会话之前调用此拦截器,它将被错误地识别为超时。
The following line in your configuration is configuring your session timeout interceptor as the only interceptor in the stack, which is certainly not what you want.
Instead, you need to define a stack that contains all of the interceptors you want to use and define that as your default.
Also, the interceptor you have built is not actually detecting that a session has timed out, but rather just that a session is empty. I'm not sure what is populating your session, but if this interceptor is invoked prior to a new session being properly populated, it will be erroneously identified as timed out.