File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter URL mapping 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 "Filter URL mapping" Watch "Filter URL mapping" New topic

Filter URL mapping

O. Ilamah

Joined: Aug 02, 2005
Posts: 4
Hello Everyone,

I would like to deploy a filter to log requests to all jsp's located within a sub directory of the applications context root .

Here is the scenerio:

Context root : testapp
Required : Filter requests to all jsp's in testapp/admin/ for example testapp/admin/manage.jsp

I configured the following in web.xml:


But the app server throws an exception : . . . . . . + "Invalid <url-pattern> /admin/*.jsp in filter mapping" . . . .

When I change to


everything works fine. But I observed that the filter is applied to everything not just jsp's, implying that for a request for a jsp, the filter is applied to associated sub-requests for images(gif, jpg) etc contained on that jsp page. Also request for static html files are similary filtered. This I would like to avoid by filtering only requests for files with .jsp extension.

Also, the config below works.


But this applies the filter to all jsp files in the application, not only jsp's in the admin subdirectory as I require.

Can anybody see what I am doing wrong or how to solve my problem ?

Thanks in advance.
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
The url-pattern doesn't allow complex url-patterns.
I advice you to use

and in the doFilter method analyze whether the requestd resource is a jsp file or not.
I agree. Here's the link:
subject: Filter URL mapping
It's not a secret anymore!