How do you define multiple filters in JSP?

Your web application may define several different filters with a specific purpose. Consider, you define two filters AuthenFilter and LogFilter. Rest of the process will remain as explained above except you need to create a different mapping as mentioned below −


   LogFilter
   LogFilter
   
      test-param
      Initialization Paramter
   


   AuthenFilter
   AuthenFilter
   
      test-param
      Initialization Paramter
   


   LogFilter
   /*


   AuthenFilter
   /*

Filters Application Order

The order of filter-mapping elements in web.xml determines the order in which the web container applies the filter to the servlet or JSP. To reverse the order of the filter, you just need to reverse the filter-mapping elements in the web.xml file.

For example, the above example will apply the LogFilter first and then it will apply AuthenFilter to any servlet or JSP; the following example will reverse the order −


   AuthenFilter
   /*


   LogFilter
   /*
Updated on: 2019-07-30T22:30:25+05:30

841 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements