October 2018
Intermediate to advanced
590 pages
15h 5m
English
Filters are another good technology of Java EE. It is an implementation of the Chain of Responsibility design pattern. It is useful when you want to perform filtering tasks to HTTP requests before they reach servlets.
Let's create an AuditingFilter to audit requests. For demonstration purposes, we will simply write the request information to log for now.
To create a filter, we need to implement the javax.servlet.Filter interface. Or, we can extend Spring's org.springframework.web.filter.GenericFilterBean, which provides a number of handy features. Let's go with GenericFilterBean.
Here is how AuditingFilter appears:
package app.messages;...public class AuditingFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest ...Read now
Unlock full access