• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Filter URL mapping

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic