• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter URL mapping

 
O. Ilamah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic