page buffer autoFlush

<%@ page language="java" pageEncoding="UTF-8"  autoFlush="false" buffer="10kb" contentType="text/html; charset=UTF-8"%><%
//jsp.error.page.badCombo
//autoFlush="false" buffer="none"
/***
从源码 可以看出
out 最后将自动清理缓存//所以要测试 autoFlush 和 buffer 将采用 out.getBufferSize() 和 out.clear() 结合测试.
} catch (Throwable t) {
    if (!(t instanceof SkipPageException)){
      out = _jspx_out;
      if (out != null && out.getBufferSize() != 0)
        try { out.clearBuffer(); } catch (java.io.IOException e) {}
      if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
    }
  } finally {
    _jspxFactory.releasePageContext(_jspx_page_context);
  }
}
}
       
*****/

/*
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
response.flushBuffer();
*/
String name="";
for(int i = 0 ;i<1024*10; i++){
    name+="D";
}





//这里name 的长度为10240 个字符 刚好 等于buffer ="10kb" 大小 如果 此时 autoFlush="false"
//将抛出 //java.io.IOException: Error: JSP Buffer overflow (if autoFlush="false"  and  buffer  can't flush)
//note :  jsp 页面 一个回车换行 out('\n');out('\r') 输入2个字符.

System.out.println(" ===========name : " +name.length());
System.out.println(" =========== buffer size : " + out.getBufferSize());
System.out.println(" =========== out.isAutoFlush()  : " + out.isAutoFlush());
out.print(name);

//out.print("AAAAAAAAAAAAAAAAA");
//清除buffer 抛出异常 如果buffer 已经被清空
//out.clear();
//刷新buffer 输出到页面
out.flush();
//清除buffer 不会抛出异常
//out.clearBuffer();

out.print("<br/> BBBBBBBBBBBBBBBBB");
System.out.println(" =========== buffer size : " + out.getBufferSize());

//这里假设 可以 使得 out 最后不会调用out.clearBuffer();//可惜不可能
//  out = _jspx_out;  即使你这样设置了  tomcat 源码还是会帮你还原
/*
} catch (Throwable t) {
    if (!(t instanceof SkipPageException)){
      out = _jspx_out;
      if (out != null && out.getBufferSize() != 0)
        try { out.clearBuffer(); } catch (java.io.IOException e) {}
      if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
    }
  } finally {
    _jspxFactory.releasePageContext(_jspx_page_context);
  }
}
}
*/
out=null;
%><% //if out=null 后面不能出现空行 回车 out已经为空了...会有异常
%><%--
//out.isAutoFlush();
//out.close();

System.out.println(" =========== buffer size : " + response.getBufferSize());
Thread.sleep(3000);
/**
    public boolean isCommitted()
    Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.
**/

System.out.println(" =========== response is commited? /  : " + response.isCommitted());
//response.setBufferSize(1024*10);
//response.setBufferSize(10);
/**
public void flushBuffer()
                 throws java.io.IOException
    Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
**/
//response.flushBuffer();
//response.resetBuffer();
//response.reset();

System.out.println(" =========== buffer size : " + response.getBufferSize());



/**
public void resetBuffer()
    Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.

public void reset()
    Clears any data that exists in the buffer as well as the status code and headers.
**/
    System.out.println(" =========================B");
    //response.sendRedirect("http://www.baidu.com");
   
    /*
        response.sendRedirect("whoami.jsp");
        Enter:
            http://192.168.1.14:8082/kathleen/a.jsp
        To:
            http://192.168.1.14:8082/whoami.jsp
           
        response.sendRedirect("whoami.jsp");
        To:
            http://192.168.1.14:8082/kathleen/whoami.jsp
    */
    //return;
    //if  you send this it will show IllegalStateException
    //because you had commit response.
    //response.sendRedirect("whoami.jsp");
    /**will not print in tomcat console**/
    System.out.println(" =========================A");
   
   
--%>
 



参考文档 :http://www.scribd.com/doc/34446565/JSP-Out-Object-Methods

你可能感兴趣的:(thread,tomcat,jsp,cache)