HttpServletResponse: sendError(int arg0, String arg1) : HttpServletResponse « javax.servlet.http « Java by API






HttpServletResponse: sendError(int arg0, String arg1)

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Buffering extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    res.setBufferSize(8 * 1024); // 8K 
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    int size = res.getBufferSize(); // returns 8096 or greater

    log("The default buffer size is " + size);

    out.println("The client won't see this");
    res.reset();
    out.println("Nor will the client see this!");
    res.reset();
    out.println("And this won't be seen if sendError() is called");
    if (req.getParameter("param") == null) {
      res.sendError(res.SC_BAD_REQUEST, "param needed");
    }
  }
}

           
       








Related examples in the same category

1.HttpServletResponse: addCookie(Cookie arg0)
2.HttpServletResponse.SC_BAD_REQUEST
3.HttpServletResponse.SC_MOVED_TEMPORARILY
4.HttpServletResponse: encodeURL(String url)
5.HttpServletResponse: sendRedirect(String arg0)
6.HttpServletResponse: setContentType( text/html; charset=UTF-8 );
7.HttpServletResponse: setHeader(String name, String value)
8.ServletResponse: setBufferSize(int arg0)
9.HttpServletResponse: setContentType("text/vnd.wap.wml")
10.HttpServletResponse: setHeader(String name, String value) (2)
11.HttpServletResponse: setStatus(int status)