aspose file tools*
The moose likes Servlets and the fly likes Filter configuration? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter configuration?" Watch "Filter configuration?" New topic
Author

Filter configuration?

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 243

Hi, i have an application which is developed on MVC architecture using servlets JSP and java (Hibernate). I want to check weather the user is logged in on not for viewing particular pages so i want to implement a filter for that one. My doubt is how to map only "servlets"(nearly 50- 60) to that filter in web.xml file.
Thanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

Filters are applied to URL patterns, in a similar way that servlets are. If you need to apply the filter to all servlets but nothing else but servlets you must make sure the servlet URL patterns match the filter URL patterns one on one. This means that you can't have a filter URL pattern where there is no matching servlet URL pattern (because you will then filter too much), but you also can't have a servlet URL pattern where there is no matching filter URL pattern (because you will then not filter enough).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 243

I am not clear what you have posted sorry, I want to configure filter for some of my servlets only is there any way to do this..?
Pankaj Kr. Singh
Ranch Hand

Joined: Mar 31, 2011
Posts: 32

Hi mallikarjun dontamsetti,

Use the following mapping it will be applied to all your servlet.

Using this you can get ride of your problem to map filter for every servlet.
It will run for all request and response.

<filter>
<display-name>FilterDisplayName</display-name>
<filter-name>filterName</filter-name>
<filter-class>filterClassName</filter-class>
</filter>
<filter-mapping>
<filter-name>filterName</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

Except that filter mapping applies to everything, not only servlets.
mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 243

Pankaj thanks but the mapping will occur to all jsp's and servlets and every thing in application. But i need only map to some of servlets. presently i am doing like this.


is there any other way to do that
FYI: I am using servlets 2.5
Pankaj Kr. Singh
Ranch Hand

Joined: Mar 31, 2011
Posts: 32

Hi,

If you have to apply the filter to some specific servlet then you will have to mapped filter for those servelets.
If you want to run on only with servlet then use .java pattern instead of * in filter url mapping.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

That's only going to work if all servlets have a URL mapping ending with .java. I've yet to see the first setup where this is the case.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter configuration?