首页 > 代码库 > structs2.8创建拦截器

structs2.8创建拦截器

控制层

 1 public class PrintUsername {
 2     private String username;
 3 
 4     public String getUsername() {
 5         return username;
 6     }
 7 
 8     public void setUsername(String username) {
 9         this.username = username;
10     }
11 
12     public String execute(){
13         System.out.println("PrintUSrn execute()");
14         return "toPrintUsernameJSP";
15     }
16 }

配置struts.xml

 1 <struts>
 2 <package name="struct2.8" extends="struts-default">
 3 
 4     
 5     
 6     <interceptors>
 7         <interceptor name="myinterceptor" class="myinterceptor.MyInterceptor">
 8         </interceptor>
 9         <interceptor-stack name="myInterceptorStack">
10             <interceptor-ref name="defaultStack"></interceptor-ref>
11             <interceptor-ref name="myinterceptor"></interceptor-ref>
12         </interceptor-stack>
13     </interceptors>
14 
15     <default-interceptor-ref name="myInterceptorStack"></default-interceptor-ref>
16 
17     <action name="printUsername" class="controller.PrintUsername">
18         <result name="toPrintUsernameJSP">
19             /printUsername.jsp
20         </result>
21     </action>
22 </package>
23 
24 </struts>

显示层列出

 

控制台界面

技术分享

 

structs2.8创建拦截器