- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
<filter> <filter-name>LogFilter</filter-name> <filter-class>LogFilter</filter-class> <init-param> <param-name>test-param</param-name> <param-value>Initialization Paramter</param-value> </init-param> </filter> <filter> <filter-name>AuthenFilter</filter-name> <filter-class>AuthenFilter</filter-class> <init-param> <param-name>test-param</param-name> <param-value>Initialization Paramter</param-value> </init-param> </filter> <filter-mapping> <filter-name>LogFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>AuthenFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
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 −
<filter-mapping> <filter-name>AuthenFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>LogFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
- Related Articles
- What are filters in JSP?
- How do you set cookies in the JSP?
- How do you implement hit counter in JSP?
- How do you implement the auto refresh in JSP?
- How Do You Define Bandwidth and Throughput in Wireless Communications?
- How do you remove multiple items from a list in Python?
- How to use multiple resource bundle in same JSP?
- Would you recommend to define multiple Python classes in a single file?
- Calculate average from JSON data based on multiple filters JavaScript
- How can you delete a session data in JSP?
- How to define multiple CSS attributes in jQuery?
- How can you upload a file using JSP?
- How can you read a request header information in JSP?
- How do we define tuple in Python?
- How do we define lists in Python?

Advertisements