<servlet-name> inside <filter-mapping> of web.xml, what does this mean?

30,159

Have you tried Google ?

Why is it a servlet being mapped inside a tag? What does this kind of mapping imply?

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

what does <listener> do?

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

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

Share:
30,159
Jemp
Author by

Jemp

Updated on December 28, 2020

Comments

  • Jemp
    Jemp over 3 years

    I am starting to learn Struts 2. I stumbled upon this code:

    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...
    

    My question is in this part

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


    Why is it a servlet being mapped inside a <filter-mapping> tag? What does this kind of mapping imply? Also, what does <listener> do? Thanks for the replies.