总有人间一两风,填我十万八千梦

JSP out 对象的使用

JAVA/JSP Zero、J 5580℃ 0评论

out对象主要内容是向web浏览器内输出各种数据类型的内容,并且管理应用服务器上的输出缓冲区,缓冲区默认值是8KB。out对象被封装为javax.servlet.jsp.JspWriter接口,它是JSP编程过程中经常用到的一个对象。out对象的常用方法如下所示。

  • clear
  • clearBuffer
  • flush
  • isAutoFlush
  • getBufferSize
  • getRemaining
  • newLine
  • print
  • println

下面是有关方法的详细内容:

clear

As the name implies, the clear method of out object is used to clear the output buffer. This method does not write any contents to the client. An exception is thrown by this method if the buffer was flushed(清除缓冲区,如果调用了flush,将会抛出异常).

out.clear();

clearBuffer

The clearBuffer method of out object is used to clear the output buffer. This method does not write any contents to the client.The only difference between the clear method of out object and clearBuffer method is clear method throws an exception when the buffer is flushed. clearBuffer method does not throw an exception when the buffer is flushed.(这里说的很清楚了,ClearBuffer与Clear的区别就是当buffer被flush的时候是否会抛出异常)

out.clearBuffer();

flush

Two methods of out object, clear and clearBuffer are used to clear the output buffer without writing any contents to the client. If you wish to flush the buffer and write contents to the client, then you can use the flush method of out object. The flush method of out object is used to flush the buffer by writing the contents to the client.(将缓冲区的数据显示到客户端)

out.flush();

isAutoFlush

The isAutoFlush method of out object returns a true value if the output buffer is automatically flushed.(判断当前是否是autoFlush)

out.isAutoFlush()

getBufferSize

The getBufferSize method of out object is used to return the size of the buffer. The returned value of the size of the buffer is in bytes. If the output is not buffered, then the getBufferSize method returns a 0 byte.(获取缓冲区大小,如果当前缓冲区设置是none则返回null)

out.getBufferSize()

getRemaining

The getRemaining method of out object is used to return the number of empty bytes in the buffer.(用于获取当前缓冲区字节数量)

out.getRemaining();

newLine

As the name implies, the newLine method of out object is used to write a newline character to the output.(输出一个换行符)

out.newLine();

print

The print method of out object writes the value to the output without a newline character.(输出一个不含有换行符的值)

out.print("QWER");

println

The println method of out object is used to write the value to the output, including the newline character.(输出内容末尾带有换行符)

out.println("DF");

 

转载请注明:悠然品鉴 » JSP out 对象的使用

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址