Thursday, May 22, 2008

Jsp buffer and autoFlush - Refresh

 

<%@ page buffer=sizekb %>

Gives the size of the page buffer in kb or none for no buffer. Default 8kb. If buffer is none, all output is immediately flushed.

JSP 1.0 gives page writers flexibility by buffering its output before sending the response to HTTP. The buffering allows error recovery and forwarding, even after generating some content. Once the buffer has filled, it will be flushed. So applications must still detect their errors early.

The following example generates an XML section (for variety). If the form's query is missing the 'name' parameter, it will redirect the results.

          <?xml version='1.0'?>
          <form>
          <%
          if (request.form["name"] == null)
          pageContext.forward("redo-form.jsp");
 
          for (var name in request.form) {
          out.print("<" + name + ">");
          out.print(request.form[name]);
          out.println("</" + name + ">");
          }
          %>
          </form>
        

<%@ page autoFlush="true" %>

Tells JSP to flush the page buffer when it fills. Default is true.

If autoFlush is false, the JSP engine will throw an exception if the buffer overflows.

 

No comments:

Post a Comment