code: public static void writeEscapedForHTML(String s, Writer w)
      throws IOException {
          PrintWriter out = new PrintWriter(w);
          BufferedReader reader = new BufferedReader(new StringReader(s));
          String line;
          while((line=reader.readLine()) != null){
              out.println(StringEscapeUtils.escapeHtml(line));
          }
      }
docs: Utility method for writing a (potentially large) String to a JspWriter,
  escaping it for HTML display, without constructing another large String
  of the whole content.
  @param s String to write
  @param out destination JspWriter
  @throws IOException