• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter configuration?

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except that filter mapping applies to everything, not only servlets.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic