1.定义拦截器类实现Interceptor接口
2.在struts的配置文件中:
<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.ObjectFactory" value="spring"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<!-- 指定访问action的后缀类型 -->
<constant name="struts.action.extension" value="action"></constant>
<package name="default" namespace="/myaction" extends="struts-default">
<!--
在bean.xml中定义拦截器:
写入自己定义的拦截器
编写拦截器栈,包括系统默认的拦截器和自己定义的拦截器
最后再想调用拦截器的action中加入拦截器栈
-->
<interceptors>
<interceptor name="mi" class="com.interceptor.MyInterceptor"></interceptor>
<interceptor-stack name="mistack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="mi"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mistack"></default-interceptor-ref>
<global-results>
<result name="success">/WEB-INF/page/hello.jsp</result>
</global-results>
<action name="hello_*" class="com.action.Hello" method="{1}">
<interceptor-ref name="mistack"></interceptor-ref>
</action>
</package>
<!-- Add packages here -->
</struts>