FileDocCategorySizeDatePackage
AsciiResult.javaAPI DocExample1384Fri Feb 21 13:14:12 GMT 2003None

AsciiResult

public class AsciiResult extends HttpServlet

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

    res.setContentType("text/html");
    ServletOutputStream out = res.getOutputStream();

    // ServletOutputStream has println() methods for writing strings
    // The println() call only works for single-byte character encodings
    // If you need multibyte, make sure to set the charset in the Content-Type
    // and use for example out.write(str.getBytes("Shift_JIS")) for Japanese 
    out.println("Content current as of");
    out.println(new Date().toString());

    // ... retrieve a database ResultSet here ...
    ResultSet resultSet = null;

    try {
      InputStream ascii = resultSet.getAsciiStream(1);
      returnStream(ascii, out);
    }
    catch (SQLException e) {
      throw new ServletException(e);
    }
  
public static voidreturnStream(java.io.InputStream in, java.io.OutputStream out)

    byte[] buf = new byte[4 * 1024];  // 4K buffer
    int bytesRead;
    while ((bytesRead = in.read(buf)) != -1) {
      out.write(buf, 0, bytesRead);
    }