struts2自定义拦截器
2012-09-29 08:10
309 查看
自定义拦截器,在struts.xml文件中使用这个拦截器可以对没登陆的用户进行拦截,还可以防止退出后返回还能进系统的bug
package crm.interceptor;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import crm.bean.Worker;
public class MyInterceptor extends AbstractInterceptor {
/**
* 序列号
*/
private static final long serialVersionUID = 1L;
public String intercept(ActionInvocation invocation) throws Exception {
ServletActionContext.getResponse().setHeader("Pragma", "no-cache");
ServletActionContext.getResponse().setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
ServletActionContext.getResponse().addHeader("Cache-Control", "post-check=0, pre-check=0");
ServletActionContext.getResponse().setHeader("Expires", "0");
//获取session中保存的用户信息
Map<String,Object> session=invocation.getInvocationContext().getSession();
Worker worker=(Worker)session.get("worker");
if(worker==null)
return Action.LOGIN;
else
return invocation.invoke();
}
}
package crm.interceptor;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import crm.bean.Worker;
public class MyInterceptor extends AbstractInterceptor {
/**
* 序列号
*/
private static final long serialVersionUID = 1L;
public String intercept(ActionInvocation invocation) throws Exception {
ServletActionContext.getResponse().setHeader("Pragma", "no-cache");
ServletActionContext.getResponse().setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
ServletActionContext.getResponse().addHeader("Cache-Control", "post-check=0, pre-check=0");
ServletActionContext.getResponse().setHeader("Expires", "0");
//获取session中保存的用户信息
Map<String,Object> session=invocation.getInvocationContext().getSession();
Worker worker=(Worker)session.get("worker");
if(worker==null)
return Action.LOGIN;
else
return invocation.invoke();
}
}
相关文章推荐
- struts2自定义拦截器
- Struts2-16 自定义拦截器
- struts2自定义拦截器
- struts2——自定义拦截器!!!
- struts2之自定义拦截器及拦截器生命周期分析
- JAVA_WEB Struts2学习:struts2自定义拦截器
- day03-自定义struts2拦截器
- Struts2 自定义拦截器栈后无法得到表单参数之解决办法
- Struts2自定义拦截器验证登录
- struts2中关于使用自定义的拦截器后,从页面提交过来的bean的参数的值为null的误区及解决
- 使用struts2中默认的拦截器以及自定义拦截器
- Struts2 自定义拦截器(方法拦截器)
- struts2——自定义拦截器
- 关于struts2的自定义拦截器和struts2的详细流程
- 由自定义的拦截器窥探struts2 Interceptor拦截器拦截机制
- java Struts2_用户自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器实例—登陆权限验证
- Struts2自定义拦截器实例—Session超时的处理
- struts2自定义拦截器