所有的学习我们必须先搭建好Struts2的环境(1、导入对应的jar包,2、web.xml,3、struts.xml)

第一节:拦截器简介 

    (百度百科Struts2)

    Struts2 拦截器是在访问某个Action 或Action 的某个方法,字段之前或之后实施拦截,并且Struts2 拦截器是可
    插拔的,拦截器是AOP的一种实现.
    优点:通用功能的封装,提供了可重用性;

第二节:Struts2 预定义拦截器&拦截器栈

 1 <?xml version="1.0" encoding="UTF-8" ?>
 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 <struts>
 7 
 8   <package name="manage" namespace="/" extends="struts-default">
 9       
10       <interceptors>
11           <interceptor name="myInterceptor" class="com.wishwzp.interceptor.MyInterceptor"></interceptor>
12       </interceptors>
13       
14       <action name="hello" class="com.wishwzp.action.HelloAction">
15           <result name="success">success.jsp</result>
16           
17           <interceptor-ref name="myInterceptor"></interceptor-ref>
18           <interceptor-ref name="defaultStack"></interceptor-ref>
19       </action>
20   </package>
21 
22 </struts>
struts.xml

相关文章:

  • 2021-05-29
猜你喜欢
  • 2021-12-07
  • 2021-12-11
  • 2021-09-22
  • 2021-08-08
  • 2021-06-28
相关资源
相似解决方案