struts2编写自定义拦截器filter
来源:互联网 发布:淘宝卖家体检中心链接 编辑:程序博客网 时间:2024/06/15 21:54
public class LoginedCheckInterceptor extends AbstractInterceptor {/** * */private static final long serialVersionUID = 1L;/** 拦截请求并进行登录有效性验证 */public String intercept(ActionInvocation arg) throws Exception { //取得请求的URL String url = ServletActionContext.getRequest().getRequestURL().toString(); HttpServletResponse response=ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); // response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); response.setDateHeader("Expires",0); LoginUser loginUser = null; //对登录与注销请求直接放行,不予拦截 if (url.indexOf("login.action")!=-1 || url.indexOf("exitSave.action")!=-1){ return arg.invoke(); } else{ //验证Session是否过期 if(!ServletActionContext.getRequest().isRequestedSessionIdValid()){ //session过期,转向session过期提示页,最终跳转至登录页面 return "tologin"; } else{ loginUser = (LoginUser)ServletActionContext.getRequest().getSession().getAttribute("user"); //验证是否已经登录 if (loginUser==null){ //尚未登录,跳转至登录页面 return "tologin"; }else{ return arg.invoke(); } } }}}
0 0
- struts2编写自定义拦截器filter
- struts2 自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2---自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- 232. Implement Queue using Stacks
- 广播(Broadcast)的简单用法
- 第一章 关于语言,对象
- MySql 5.7安装(随机密码,修改默认密码)
- 二分查找
- struts2编写自定义拦截器filter
- ios 泛型
- 笔记
- 第一章 对象导论 1.1抽象过程
- Unity打造简易的GalGame游戏剧本编辑引擎
- 计算某一天是星期几的算法
- HZK16汉字16*16点阵字库的使用及示例程序
- “android list avd不是内部或外部命令,也不是可运行的程序”之解决办法
- Sublime Text3 License