aspose file tools*
The moose likes Servlets and the fly likes Servlet Filters - A couple of questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Filters - A couple of questions" Watch "Servlet Filters - A couple of questions" New topic

Servlet Filters - A couple of questions

Andreas Markitanis

Joined: Apr 15, 2010
Posts: 21
Hi guys

I am pretty new to servlet filters and just want to ask a couple of questions

1. Can you have one filter with two url-patterns tags in web.xml (for example one for *.jsp and one for /servlet/*)?

In other words, is the following piece of code allowed in the deployment descriptor (web.xml)?

2. If I use a Filter to intercept all requests (your url-pattern is /* ) which will redirect the user to index.jsp if there is no user attribute stored in the session I get the following behaviour

- accessing a restricted page when there is no session redirects the user to the index page
- accessing a restricted servlet will produce an IllegalStateException.

Does that mean I have to create two different filters, one to cater for jsp, and one for servlets?

The following is a snippet of code which fails to exhibit the behaviour stated in 2.

Any help is much appreciated.

Andreas Markitanis

Joined: Apr 15, 2010
Posts: 21
Following my post above,

Should the chain.doFilter(request, response) method be called only if access is granted to propagate the request and response to the next filter in the chain?

If so, isn't my problem fixed with the following snippet of code?

sanjeev tuli

Joined: Feb 20, 2008
Posts: 1
yes it
I agree. Here's the link:
subject: Servlet Filters - A couple of questions
Similar Threads
NullPointerException in AutoScrollPhaseListener
jsf tutorial
org.springframework.web.HttpSessionRequiredException: Session attribute 'user' required - not found
How to configure multiple *.do in web.xml file
Setting the path of servlet and jsp pages