问题描述
packageinterceptot;importjava.util.Iterator;importjava.util.Map;importcom.opensymphony.xwork2.ActionContext;importcom.opensymphony.xwork2.ActionInvocation;importcom.opensymphony.xwork2.interceptor.AbstractInterceptor;publicclassMyInterceptotextendsAbstractInterceptor{/****/privatestaticfinallongserialVersionUID=1L;@OverridepublicStringintercept(ActionInvocationinvocation)throwsException{System.out.println("拦截器");ActionContextctx=invocation.getInvocationContext();Stringobject=ctx.toString();Mapsession=ctx.getSession();System.out.print("session");print(session);ObjectcAction=ctx.getActionInvocation().getAction();MapuApplication=ctx.getApplication();System.out.print("uApplication:");print(uApplication);MapuParameters=ctx.getParameters();System.out.print("uParameters:");print(uParameters);MapuContextMap=ctx.getContextMap();System.out.print("uContextMap:");print(uContextMap);Stringbean=ctx.getName();System.out.println(bean);if(bean.equals("login")||bean.equals("registrat")||session.get("user")!=null){System.out.println("拦截器通过");returninvocation.invoke();}System.out.println("拦截器没通过");return"login";}publicvoidprint(Mapmap){Iteratorit=map.keySet().iterator();if(it.hasNext()){System.out.println(it.next());}}}结果:uParameters:user.usernameuContextMap:com.opensymphony.xwork2.ActionContext.parameterslogin拦截器通过bean+密码Hibernate:selectuser0_.idasid0_,user0_.`username`asusername2_0_,user0_.`password`aspassword3_0_fromuseruser0_whereuser0_.`username`=?[]
解决方案
解决方案二:
没看懂。条件满足不是都有输出吗?
解决方案三:
拦截器通过只输出了一次
解决方案四:
而且拦截器不拦截访问其他网页的请求