• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Who is First Filter or Servlet

 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we will define both Filter and Servlet mapping in web.xml with same URL pattern.
If we call the URL which one is called First.
Servlet or Filter.

Thanx
sanjay
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filters. Mapping purpose is differnt for filter and servlets.
 
John Wolf
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To confirm, it is the chain.doFilter(request, response) in the Filter above, that calls the servlet with the same url-mapping? Right?

What I am little confused on is ... if filters have matching url-pattern but do not have a servlet-name mapped and there is no servlet with a matching url-mapping, then do filters run on their own with no servlet being called at all.
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
sumit

Think ,that whats the use of filter and servlet .Then the dought will be claer that FILTER will always be called first b'se its Intercepting request and response .

Thanx
Sanjay
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Your Quote

What I am little confused on is ... if filters have matching url-pattern but do not have a servlet-name mapped and there is no servlet with a matching url-mapping, then do filters run on their own with no servlet being called at all.


I think the container first find the matching Servlet. If the matching servlet is found then only it execute the filters that matched the given URL before executing the Servlet. The Filters can terminate the processing in between, if required. If no Servlet mapping is found, no filter will run even though the filters have matching URL.

Thanks
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Also, The code after doFilter(..) method of FilterChain method executed after the Servlet.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic