@Controller
@Namespace("/category")
@ParentPackage("news")
@InterceptorRef(value = "isLoginInterceptor")
public class CategoryAction extends ActionSupport {
虽然这样子注解就可以应用拦截器,但spring并不会自动帮你生成注解器实例,还需要在strutsx.xml中配置
<struts>
<!-- 请求参数的编码方式-->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开-->
<constant name="struts.action.extension" value="action,do,html"/>
<!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.devMode" value="false"/>
<!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 指定由spring负责action对象的创建 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 是否开启动态方法调用-->
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<!--拦截器,必须配置默认的拦截器栈,不然在请求时会丢失请求参数-->
<package name="news" extends="struts-default">
<interceptors>
<interceptor name="loginCheckInterceptor" class="com.news.interceptor.IsLoginInterceptor"></interceptor>
<interceptor-stack name="isLoginInterceptor">
<interceptor-ref name="loginCheckInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
</package>
</struts>