aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Who is First  Filter or Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Who is First  Filter or Servlet" Watch "Who is First  Filter or Servlet" New topic
Author

Who is First Filter or Servlet

Sanjay pts
Ranch Hand

Joined: Nov 07, 2000
Posts: 357
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


Eat JAVA, Drink JAVA, Sleep Java
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Filters. Mapping purpose is differnt for filter and servlets.


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
John Wolf
Ranch Hand

Joined: Feb 18, 2002
Posts: 64
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

Joined: Nov 07, 2000
Posts: 357
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

Joined: Dec 04, 2004
Posts: 950
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

Joined: Dec 04, 2004
Posts: 950
Hi,

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

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Who is First Filter or Servlet