Two Laptop Bag*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Filter URL mapping" Watch "Filter URL mapping" New topic
Author

Filter URL mapping

O. Ilamah
Greenhorn

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:

<filter-mapping>
<filter-name>superfilter</filter-name>
<url-pattern>/admin/*.jsp</url-pattern>
</filter-mapping>

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

When I change to

<filter-mapping>
<filter-name>superfilter</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>


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.

<filter-mapping>
<filter-name>superfilter</filter-name>
<url-pattern>/*.jsp</url-pattern>
</filter-mapping>

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
<filter-mapping>
<filter-name>superfilter</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>

and in the doFilter method analyze whether the requestd resource is a jsp file or not.
 
Consider Paul's rocket mass heater.
 
subject: Filter URL mapping
 
Similar Threads
Filter authentication won't display error page
Filter not working with jsp:include
Filter Behavior
How to Servlet Filtering?
filter validation