首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2拦截器证验登陆状态

2012-11-16 
struts2拦截器验证登陆状态import?java.util.HashMap??import?java.util.Map??import?com.opensymphony.

struts2拦截器验证登陆状态

import?java.util.HashMap;??import?java.util.Map;??import?com.opensymphony.xwork2.Action;??import?com.opensymphony.xwork2.ActionInvocation;??import?com.opensymphony.xwork2.interceptor.AbstractInterceptor;??import?com.opensymphony.xwork2.ActionContext;??public?class?RightInterceptor?extends?AbstractInterceptor?{????????@Override??????public?String?intercept(ActionInvocation?invocation)?throws?Exception?{??????????//System.out.println("拦截器开始验证");??????????try??????????{??????????????ActionContext?actionContext?=?ActionContext.getContext();??????????????Map<String,Object>?session?=?actionContext.getSession();??????????????String?user=session.get("usercode").toString();?????????????????//当前用户session无效且访问的action不是登录action时,执行拦截,跳转??????????????if((user==null?||?user.equals(""))?&&?!invocation.getAction().getClass().getName().equals("登录action"))???????????????{??????????????????return?Action.LOGIN;??????????????}??????????}??????????catch(Exception?e)??????????{??????????????e.printStackTrace();??????????????return?Action.LOGIN;??????????}??????????//System.out.println("拦截器通过验证");??????????return?invocation.invoke();//执行访问的action??????}????}??

热点排行