9.10. Example: A Replacement Filter
This section presents one common application of the CharArrayWrapper shown in the previous section: a filter that changes all occurrences of a target string to some replacement string.
A Generic Replacement Filter
Listing 9.15 presents a filter that wraps the response in a CharArrayWrapper, passes that wrapper to the doFilter method of the FilterChain object, extracts a String that represents all of the resource’s output, replaces all occurrences of a target string with a replacement string, and sends that modified result to the client.
There are two things to note about this filter. First, it is an abstract class. To use it, you must create a subclass that provides implementations of the getTargetString ...
Get More Servlets and JavaServer Pages™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.