res.setContentType("text/html");
// Set up a PrintStream built around a special output stream
ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
PrintWriter out = new PrintWriter(bytes, true); // true forces flushing
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World</BIG>");
out.println("</BODY></HTML>");
// Set the content length to the size of the buffer
res.setContentLength(bytes.size());
// Send the buffer
bytes.writeTo(res.getOutputStream());