日期:2014-05-19 浏览次数:20796 次
@SuppressWarnings("serial") public class MyInterceptor extends AbstractInterceptor { @SuppressWarnings("unchecked") @Override public String intercept(ActionInvocation arg0) throws Exception { // HttpSession hs = ServletActionContext.getRequest().getSession(); // String username = (String) hs.getAttribute("username"); // ActionContext ac = arg0.getInvocationContext(); Map session = ac.getSession(); System.out.println(session.size()); Userinfo userinfo = (Userinfo) session.get("user"); if(userinfo==null){ return Action.LOGIN; }else{ return arg0.invoke(); } } }
<interceptors> <interceptor name="myInterceptor" class="cn.com.MyInterceptor"/> <interceptor-stack name="myInterceptorStack"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="myInterceptor"/> </interceptor-stack> </interceptors> <action name="list_*" class="cn.com.action.TheAction" method="{1}"> <!--拦截的TheAction中的方法--> <interceptor-ref name="myInterceptorStack" /> </action>