Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet Filter for all requests

I am wondering, how can I set in the web.xml a Filter that is called on every request?

like image 362
fernandohur Avatar asked Oct 31 '11 04:10

fernandohur


2 Answers

just create a filter, and map it to /*

e.g.

    <filter>
        <filter-name>MyFilter</filter-name>
        <filter-class>com.mycompany.MyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>MyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
like image 128
aishwarya Avatar answered Oct 08 '22 07:10

aishwarya


Add a filter mapping with '*' wildcard.

  <filter-mapping>
   <filter-name>TestFilter</filter-name>
   <url-pattern>*</url-pattern>
 </filter-mapping>
like image 40
Saurabh Saxena Avatar answered Oct 08 '22 08:10

Saurabh Saxena