Servlet và JSP Filter là các lớp Java dùng trong lập trình Servlet/JSP cho các mục đích:
- Chặn request từ client trước khi truy cập tài nguyên backend.
- Thao tác response từ server trước khi gửi trả client.
Các loại filter theo đặc tả:
- Authentication Filters
- Data compression Filters
- Encryption Filters
- Filters that trigger resource access events
- Image Conversion Filters
- Logging and Auditing Filters
- MIME-TYPE Chain Filters
- Tokenizing Filters
- XSL/T Filters That Transform XML Content
Filter triển khai trong file deployment descriptor web.xml và map đến servlet/JSP name hoặc URL pattern. File web.xml nằm ở <Tomcat-installation-directory>\conf.
Khi JSP container khởi động web app, nó tạo instance cho mỗi filter khai báo trong web.xml. Filter thực thi theo thứ tự khai báo trong deployment descriptor.