JSP.3.3 Buffering


The JSP container buffers data (if the jsp directive specifies it using the buffer attribute) as it is sent from the server to the client. Headers are not sent to the client until the first flush method is invoked. Therefore, none of the operations that rely on headers, such as the setContentType , redirect , or error methods , are valid until the flush method is executed and the headers are sent.

JSP 1.1 includes a class that buffers and sends output, javax.servlet.jsp.Jsp Writer . The JspWriter class is used in the _jspPageService method as in the following example:

 import javax.servlet.jsp.JspWriter;  static JspFactory _jspFactory = JspFactory.getDefaultFactory();  _jspService(<SRequest> request, <SResponse> response) {      // initialization of implicit variables...       PageContext pageContext = _jspFactory.createPageContext(                                this,                                 request,                                 response,                                 false,                                 PageContext.DEFAULT_BUFFER,                                 false                             );       JSPWriter out = pageContext.getOut();       // ....       // .... the body goes here using "out"       // ....       out.flush();  } 

You can find the complete listing of javax.servlet.jsp.JspWriter in Section JSP.6.1.2.

With buffering turned on, you can still use a redirect method in a scriptlet in a . jsp file, by invoking response.redirect(someURL) directly.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net