首先我们需要定义 一个拦截器
里面实现的代码很少 主要在strts.xml文件配置里
protected String doIntercept(ActionInvocation invocation) throws Exception { User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user"); if(user == null){ return "login"; } return invocation.invoke(); }
struts配置 定义一个全局结果
<!--配置拦截器 --> <interceptors> <interceptor name="BosLoginInterceptor" class="com.cb.bos.web.interceptor.BosLoginInterceptor"> <param name="excludeMethods">login</param> </interceptor> <interceptor-stack name="mystack"> <interceptor-ref name="BosLoginInterceptor"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <!--指定默认栈 --> <default-interceptor-ref name="mystack"/> <global-results> <result name="login">/login.jsp</result> </global-results>