• Servlet
  • JSP
  • SQL Tutorial
  • JavaScript
  • Spring
  • RubyonRails
  • Core Java
  • jQuery
  • Struts

  • <

    Servlet HttpResponse Tutorial

    Java HttpResponse is used to send back the response to the client.The response consists of status line, some response headers, a blank line,the document,redirect.


    Servlet HttpResponse Methods


  • String getCharacterEncoding()
  • String getContentType()
  • ServletOutputStream getOutputStream()
  • java.io.PrintWriter getWriter()
  • void setCharacterEncoding
  • void setContentLength(int len)
  • void setContentType(java.lang.String type)
  • void setBufferSize(int size)
  • int getBufferSize()
  • void flushBuffer()
  • boolean isCommitted()
  • void reset()
  • Servlet HttpResponse Example


    
    
    response.setHeader("Content-Type", "text/plain"); 
    
    PrintWriter writer = response.getWriter(); 
    
    writer.write("This is just plain text"); 
    


    Headers


    HttpReponse also contain HTTP headers. Headers must be set before any data is written to the response.


    response.setHeader("Header-Name", "Header Value");
    


    Content-Type

    Response content type for HTML is text/html.


    response.setHeader("Content-Type", "text/html");
    
















    © copyright 2017-2021 Completedone pvt ltd.