访问struts2的action页面出现白板问题
访问struts2的action页面出现白板问题
故需要设置拦截此action的拦截栈,
<bean id="authenticationInterceptor" class="com.cosl.util.interceptor.AuthenticationInterceptor"></bean><!--权限拦截器 -->
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="struts-my" extends="json-default"> <interceptors> <!-- 判断是否登录 和 是否有访问权限 --> <interceptor name="auth" class="authenticationInterceptor"/><!-- 这是com.cosl.util.interceptor.AuthenticationInterceptor的拦截器,在applicationContext.xml文件里实例化了 --> <interceptor-stack name="myStack"> <interceptor-ref name="auth"></interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="myStack"></default-interceptor-ref> <default-action-ref name="notFound"/> <global-results> <result name="noLogin" type="redirect">/pages/Developer/loginJsp</result> <result name="noPower" type="redirect">/no_power.jsp</result> </global-results> <action name="notFound" class="com.cosl.util.CommonAction" method="notFound"> <result name="success">/not_found.jsp</result> </action> </package> </struts>
<package name="Diaocha" extends="struts-my" namespace="/pages/Diaocha"> <action name="diaochaJsp" class="com.cosl.action.DiaochaAction" method="diaochaJsp"> <interceptor-ref name="defaultStack"/><!-- 这儿让我调试了4个小时,直接访问action没出任何结果,因为被interceptor拦截了 --> <result name="diaochaJsp">/admin/editPasswordJsp.jsp</result> </action> </package>
那是因为我访问的action被如下代码拦截了,而我所访问的action是还没登陆时就访问的,也就是所非登录状态访问的action,被下面的拦截器所拦截,
public class AuthenticationInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub Map map=invocation.getInvocationContext().getSession(); if(map.get("user")!=null) { //return "noLogin"; return invocation.invoke(); }else{ //获得登录用户的权限 } return null; } }