Servlet Filter for all requests

fernandohur picture fernandohur · Oct 31, 2011 · Viewed 14.3k times · Source

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

Answer

aishwarya picture aishwarya · Oct 31, 2011

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>