我正在用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中请求的数据已经被拦截了,只是页面不跳转,求各位给出意见???
谢谢
<!-- 定义权限控制拦截器 -->
<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中请求的数据已经被拦截了,只是页面不跳转,求各位给出意见???
谢谢
<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>