拦截器不起作用
struts2.xml
<package name="houserent" extends="struts-default" namespace="/">
<interceptors>
<interceptor name="RegisterInterceptor" class="com.accp.dao.util.GenericDaoSupport"></interceptor>
</interceptors>
<global-results>
<result>${result}</result>
<result name="error">${result}</result>
<result name="input">${result}</result>
<result name="login">${result}</result>
<result name="none">${result}</result>
</global-results>
<action name="user_*" class="userAction" method="{1}" >
<interceptor-ref name="RegisterInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="house_*" class="com.accp.action.HouseAction" method="{1}"/>
<action name="*">
<result>/index.jsp</result>
</action>
</package>
类
public class RegisterInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation ai) throws Exception {
UserAction userAction=(UserAction) ai.getAction();
System.out.println(userAction.getUser().getName());
return Action.SUCCESS;
}
}
我开了调试打了断点还是进不来
[解决办法]
楼主你上面<interceptor name="RegisterInterceptor" class="com.accp.dao.util.GenericDaoSupport"></interceptor>
这里你知道的拦截器是com.accp.dao.util.GenericDaoSupport这个类根本不是你的RegisterInterceptor 这个类
[解决办法]
楼主对拦截的配置应该不是很清楚
给你段例子
<interceptors>
<interceptor name="autherInterceptor" class="com.dev.web.interceptor.AutherInterceptor"/>
<interceptor-stack name="customeStack">
<!--自定义拦截器-->
<interceptor-ref name="autherInterceptor"/>
<!--默认的拦截器-->
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="customeStack" />