我正在用ssh做一个项目。 想用struts2的拦截器拦截所有的action请求,若用户已登录则继续访问action,若用户未登录则跳转到登录页面,我的拦截器配置文件是这样写的:<package name="my-default" extends="json-default">    
     <!-- 定义权限控制拦截器 -->
     <interceptors>
     <interceptor class="com.tsz.interceptor.AuthorityInterceptor" name="authority" />
     <interceptor-stack name="mydefault">
     <interceptor-ref name="defaultStack"></interceptor-ref>
     <interceptor-ref name="authority"></interceptor-ref>
     </interceptor-stack>
     </interceptors>
    
     <!-- 重新定义默认拦截器 -->
     <default-interceptor-ref name="mydefault" />
    
     <!-- 定义全局处理结果 -->
     <global-results>
     <result name="login" type="redirect">/login.html</result>
     </global-results>
    </package>对应的拦截器为:public class AuthorityInterceptor extends AbstractInterceptor { @Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
Map<String,Object> session = ctx.getSession();
Object object = session.get("name");
if(object != null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}}ssh中得struts版本为 struts2.2.1.1.jar, 但页面<result name="login" type="redirect">/login.html</result>不跳转。  action中请求的数据已经被拦截了,只是页面不跳转,求各位给出意见???
谢谢

解决方案 »

  1.   

    把你自定义的拦截器放置到你定义的拦截器集的上面:<!-- 定义权限控制拦截器 -->
      <interceptors>
      <interceptor class="com.tsz.interceptor.AuthorityInterceptor" name="authority" />
      <interceptor-stack name="mydefault">  <interceptor-ref name="authority"></interceptor-ref>
      <interceptor-ref name="defaultStack"></interceptor-ref>  </interceptor-stack>
      </interceptors>
      

  2.   

    你说:AuthorityInterceptor 这个拦截器中的代码有被执行到吧。
      

  3.   

    执行到了   而且整个login.html被当做JSON格式的数据传前台了,是不是因为继承了json-default啊
      

  4.   

    我的也犯了这个错,后来发现action配置的result="login"返回json对象的配置 。原来重复了