struts2的拦截器主要是拦截action?

来源:百度知道 编辑:UC知道 时间:2024/09/24 14:04:36

struts2 拦截器拦截 action没错
但绝不是上面几位说的那样
struts2的 interceptor 类似于 Spring中的AOP ,在执行某个方法时拦截他,在之前后执行某些代码
配置是在 struts.xml 中添加<interceptors>

不是的唉 可以在web.xml里面设置的
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.teamsun.itcc.webroot.FilterDispatcher</filter-class>

</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

对,是只拦截action请求,默认的拦截后缀是action,你可以设置成其他的

web.xml里<url-pattern>/*</url-pattern>设成这样的话过滤器对所有请求都起作用