8

我开始学习 Struts 2。我偶然发现了这段代码:

web.xml

...some other codes...

<filter>
    <filter-name>MyFilter</filter-name>
    <display-name>MyFilter</display-name>
    <filter-class>com.xxx.yyy.zzz.MyFilter</filter-class>
</filter>

<filter-mapping>
   <filter-name>MyFilter</filter-name>
   <servlet-name>MyAction</servlet-name>
</filter-mapping>

<listener>
   <listener-class>com.xxx.yyy.StrutsListener</listener-class>
</listener> 

<servlet>
    <servlet-name>MyAction</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>paramName1param-name>
        <param-value>paramVal1</param-value>
    </init-param>
    <init-param>
        <param-name>paramName2</param-name>
        <param-value>paramVal2</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

...some other codes...

我的问题在这部分

 <filter-mapping>
      <filter-name>MyFilter</filter-name>
      <servlet-name>MyAction</servlet-name>
 </filter-mapping>


为什么它是一个被映射到<filter-mapping>标签内的 servlet?这种映射意味着什么?还有,有什么作用<listener>?感谢您的回复。

4

1 回答 1

7

你试过谷歌吗?

为什么它是一个被映射到标签内的 servlet?这种映射意味着什么?

阅读:http ://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/web_xml.html#1039330

<listener>什么?

http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/web_xml.html#1039300

示例:http: //tomcat-configure.blogspot.in/2009/01/tomcat-context-listener-example.html

于 2012-07-26T03:47:26.057 回答