xml. The doModification method uses the regular
expression-based String.replaceAll method to replace every
occurrence of the target string with the replacement string. The
parent class also provides an empty body for the destroy method.
2. A wrapped response object. The doFilter method, inherited
from ModificationFilter, wraps the ServletResponse object
in a StringWrapper and passes that wrapper to the doFilter
public HttpServletRequest getRequest() {
return(request);
}
/** Saving off the response object for potential use by the child
* class.
*/
public HttpServletResponse getResponse() {
return(response);
}
public void init(FilterConfig config) {
// Save FilterConfig object for later use by subclasses
this.config = config;
}
public void destroy() {}
}
Listing 5.17 ModificationFilter.java (continued)
Chapter 5 ?– Servlet and JSP Filters 240
method of the FilterChain object. After this call completes, all
other filters and the final resource have executed and the output is
inside the wrapper. So, the original doFilter extracts a String that
represents all of the resource??™s output and passes it to the doModification
method, which performs some modifications of the output.
Finally, doFilter sends that modified result to the client by supplying
the modified String to the write method of the PrintWriter
that is associated with the original response.
3. Registration with the JSP page that promotes filtersRus.
Pages:
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292