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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值