UTF8.javaAPI DocExample1234Thu Apr 05 20:21:46 BST 2001None


public class UTF8 extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    try {
      // Get a reader to read the incoming data
      BufferedReader reader = req.getReader();

      // Get a writer to write the data in UTF-8
      res.setContentType("text/html; charset=UTF-8");
      //PrintWriter out = res.getWriter();
      PrintWriter out = new PrintWriter(
        new OutputStreamWriter(res.getOutputStream(), "UTF8"), true);

      // Read and write 4K chars at a time
      // (Far more efficient than reading and writing a line at a time)
      char[] buf = new char[4 * 1024];  // 4Kchar buffer
      int len;
      while ((len =, 0, buf.length)) != -1) {
        out.write(buf, 0, len);
    catch (Exception e) {
      getServletContext().log(e, "Problem filtering page to UTF-8");
public voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    doGet(req, res);