user3091495
user3091495

Reputation: 1

how to filter all the request through custom filter in spring mvc?

I am new to springs so help me out.... I need to know the web.xml configuration to filter all my request through a custom filter....

i.e

This is my normal web.xml

     <servlet>
 <servlet-name>controller</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
     </servlet>

     <servlet-mapping>
 <servlet-name>controller</servlet-name>
 <url-pattern>/</url-pattern>
     </servlet-mapping>

now what changes should i make to my web.xml so that all my requests pass through custom filter... Thanks in advance.

Upvotes: 0

Views: 1825

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279990

If you are talking about a javax.servlet.Filter, the configuration is as follows in the web.xml.

<filter>
    <filter-name>custom-filter</filter-name>
    <filter-class>your.filter.type.MyFilter</filter-class>
    <!-- Other options -->
</filter>

<filter-mapping>
    <filter-name>custom-filter</filter-name>
    <url-pattern>/*</url-pattern>
    <!-- Other options -->
</filter-mapping>

You can read all the configuration options here.

Upvotes: 2

Related Questions