• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter Mapping Doubt

 
Srividhya Kiran
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers

Consider this code..


<servlet>
<servlet-name> MyServlet </servlet-name>
<servlet-class> com.example.MyServlet </servlet-class>
</servlet>

<servlet-mapping>
<servlet-name> MyServlet </servlet-name>
<url-pattern> /MyServlet </url-pattern>
</servlet-mapping>

<filter>
<filter-name> MyFilter </filter-name>
<filter-class> com.example.MyFilter </filter-class>
</filter>

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

Can someone explain me how the container does filter mapping?

Thanks
Srividhya
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine you have an HTTP request for "/MyServlet". The web container will create a processing chain like this request->MyFilter->MyServlet.

Now imagine a different HTTP request for "/index.jsp". In this case, the MyServlet servlet is not applicable to the request and therefore the MyFilter filter is also not applicable.

Given these servlet and filter mappings, "/MyServlet" is the only HTTP request URL that will be handled by the filter and this is because "/MyServlet" is the only URL pattern that matches the MyServlet servlet.

Make sense?

Cheers,
Bryan
 
Srividhya Kiran
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bryan. So basically the container once receives the request for /MyServlet it goes and checks in the <servlet-mapping> that has the matching URL, then finds the servlet name and goes to the <filter-mapping> where it finds the matching <filter-name> and calls that particular filter. Once filter finishes, the container calls the correspoding servlet with the name given in <servlet-name>. Correct me If I am wrong.

Srividhya
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think , you are correct
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic