Tutorial :Is it possible to use wildcards within J2EE - fitlers?



Question:

I would like to apply a filter to severl url endings. The next configuraiton seems to work.

<filter>      <filter-name>LanguageFilter</filter-name>      <filter-class>filters.LanguageFilter</filter-class>  </filter>  <filter-mapping>      <filter-name>LanguageFilter</filter-name>      <url-pattern>*.do</url-pattern>  </filter-mapping>  <filter-mapping>      <filter-name>LanguageFilter</filter-name>      <url-pattern>*.xml</url-pattern>  </filter-mapping>  

Originally I asked if it was possible to use wildcards such as:

    <url-pattern>*.do|*.xml</url-pattern>  

But it does not seem to be possible.


Solution:1

There is no notion of such an operator in the standard, so you need two mappings. The specification of the mappings is available in the servlet specification. See this article for a link and section.


Solution:2

You could cheat a bit, and map /. to your filter class, then have your Filter Implementation take a parameter where .do|.xml are parsed and though your filter, technically is able to see too much, it does a simply check on whether or not you've given it an additional test, does the test, and either filter's or noops.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »