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??????}????}??