Chapter 9Improving Your Application Using Filters
- The purpose of filters
- How to create, declare, and map filters
- How to properly order your filters
- Using filters with asynchronous request handling
- Exploring practical uses for filters
- Using filters to simplify authentication
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
You can find the wrox.com code downloads for this chapter at http://www.wrox.com/go/projavaforwebapps on the Download Code tab. The code for this chapter is divided into the following major examples:
- Filter-Order Project
- Filter-Async Project
- Compression-Filter Project
- Customer-Support-v7 Project
NEW MAVEN DEPENDENCIES FOR THIS CHAPTER
There are no new Maven dependencies for this chapter. Continue to use the Maven dependencies introduced in all previous chapters.
UNDERSTANDING THE PURPOSE OF FILTERS
Filters are application components that can intercept requests to resources, responses from resources, or both, and act on those requests or responses in some manner. Filters can inspect and modify requests and responses, and they can even reject, redirect, or forward requests.
A relatively new addition to the Servlet specification, filters were added in Servlet 2.3, improved in Servlet 2.4, and haven’t really changed much since then. The javax.servlet.Filter interface is very simple and involves the HttpServletRequest and HttpServletResponse that you are already familiar with. Like Servlets, filters can be declared in the deployment descriptor, programmatically, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access