a filter that turns the entire page into lower case


I am making a filter that turns the entire page(HTML tags and all) into lower case(I don’t have to worry about legal HTML) and this is what I did so far.( It does display lower case page to tomcat windows.) Now, how do I output this to browser?

package moreservlets.filters;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;

public class LowerCaseFilter implements Filter {
  private FilterConfig config;
  public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
      throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest)request;
    HttpServletResponse res = (HttpServletResponse)response;
      // Invoke resource, accumulating output in the wrapper.
      CharArrayWrapper responseWrapper =
        new CharArrayWrapper(res);
      char[] responseChars = responseWrapper.toCharArray();
      String responseChars = responseWrapper.toString().toLowerCase();
      System.out.println(responseChars );

  /** Store the FilterConfig object in case subclasses
   *  want it.
  public void init(FilterConfig config)
      throws ServletException {
    this.config = config;

  protected FilterConfig getFilterConfig() {
  public void destroy() {}

and this is from web.xml file.



after I requested the page, I got the following as output.

Who is Participating?
bloodredsunConnect With a Mentor Commented:
write it out via the response.getOutputStream()/response.getWriter()
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.