首页 > 技术文章 > struts2 拦截器的注册在strut.xml中

MrzhangKk 2016-02-21 17:03 原文

根据需要:需要在struts.xml中注册拦截器为以下内容  根据自己的业务需要更改参数

 1    
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 
 6   <package name="test1" namespace="/" extends="struts-default">
 7             <!--<interceptors>和<global-results>是有顺序的顺序不对package会提示 -->
 8              <interceptors>
 9                  <!--check_login 为注册的拦截器名字 可以根据需要自己起名 -->
10                  <interceptor name="check_login" class="dl.zhang.interceptor.interceptor" />
11              </interceptors>
12              <!--全局结果 -->
13              <global-results>
14                  <result name="no_login">/no_login.jsp</result>         </global-results>
15  
16           <action name="test" class="dl.zhang.action.TestAction" method="test">
17             <!--拦截器拦截-->
18           <interceptor-ref name="check_login" />
19                <result>/test.jsp</result>
20              </action>
21    </package>

 

推荐阅读