`
dr2tr
  • 浏览: 142379 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Servlet tips --sending HTML information

阅读更多

1. Response basics:

     public void ServletResponse.setContentType(String);   //content type of response

     pubic PrintWriter ServletResponse.getWriter(); //charactor output

     public ServletOutStream ServletResponse.getOutputStream(); //Stream output

2. Response buffering

    ServletResponse.setBufferSize(int); //set buffer size

    ServletResponse.getBufferSize(int); //get buffer size

    ServletResponse.isCommited() // is sent?

    ServletResponse.reset(); // reset,clear all buffer content

    ServletResponse.flushBuffer(); //sent

3.Status Codes : public static final int fields of  HttpServletResponse

   HttpServletResponse.sendStatus(in t sc);   //set status, should be called before committed.

   HttpServletResponse.sendError(.., ..),  //send error and clean buffer.

4. setting a Http Header: HttpServletResponse.setHeader(..,..) and so on.

5. redirecting a request:

HttpServletResponse.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);    HttpServletResponse.setHeader("Location", site)

EQUALS TO   

HttpServletResponse.sendRedirect(site);   

6. Error Pages configured in web.xml: 

<error-page> <error-code>code</error-code><location>/error.html</location></error-page>

7. Logging: GenericServlet.log(String, [...]);

8. Configure exception page in web.xml: <error-page> <exception-type> class </exception-type> <location>./pathname</location></error-page>

9. dynamically creating a exception(error) page : mainly using request.getAttribute("javax.servlet.error.status_code");   request.getAttribute("javax.servlet.error.message");  request.getAttribute("javax.servlet.error.exception_type");

10. A long-running servlet that doesn't mind committing the response early should call checkError() regularly to determine if it can halt processing before completion.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics