Alex Rivera | Logout

Can we use regular expressions in web.xml URL patterns?

Asked 2011-12-20T04:26:55.397
35

I am writing a filter to do a specific task but I am unable to set a specific url pattern to my filter. My filter mapping is as follows:

 <web.xml>
  <filter>
     <filter-name>myFilter</filter-name>
     <filter-class>test.MyFilter</filter-class>
   </filter>

  <filter-mapping>
    <filter-name>myFilter</filter-name>
     <url-pattern>/org/test/*/keys/*</url-pattern>
   </filter-mapping>
 </web-app>

My url-pattern [ /org/test/ * /keys/ * ] is not working as I had expected.

I am calling urls from the browser like:

http://localhost:8080/myapp/org/test/SuperAdminReport/keys/superAdminReport.jsp
http://localhost:8080/myapp/org/test/Adminreport/keys/adminReport.jsp
http://localhost:8080/myapp/org/test/OtherReport/keys/otherReport.jsp

So for the URLs above the filter pattern should match. How can I achieve this?

Edit
Report

1 Answer

1

in web.xml for servlet mapping , You can apply wildcard only at the start or the end, if you try to apply the wildcard in between the mapping will not be picked.

answered 2011-12-20T04:40:47.563

Your Answer