简体   繁体   English

为什么我需要在JSP中修改buffer和autoflush属性?

[英]Why do I need to modify buffer and autoflush attributes in a JSP?


I don't understand why I need to modify the buffer and autoflush attributes in JSP, what do they do? 我不明白为什么我需要修改JSP中的buffer和autoflush属性,他们做了什么? What could happen if I do not modify them? 如果我不修改它们会发生什么?

Anything generated by the JSP page is stored in a buffer. JSP页面生成的任何内容都存储在缓冲区中。 When the buffer is full, it's sent back to the client (browser). 当缓冲区已满时,它会被发送回客户端(浏览器)。 When the buffer is flushed once, redirection or forwarding won't work because all changes to the HTTP response header must occur the first time a buffer is sent to the client. 刷新缓冲区一次后,重定向或转发将不起作用,因为HTTP响应头的所有更改必须在第一次将缓冲区发送到客户端时发生。 Similarly you cannot add cookies to the response after the first flush. 同样,在第一次刷新后,您无法将Cookie添加到响应中。

Said that, you could want to disable autoflushing and/or to increase buffer size to allow your code to add a cookie to the response very lately. 说,您可能想要禁用自动刷新和/或增加缓冲区大小,以允许您的代码最近添加cookie到响应。 However if you need to do so, your code is probably not elegant. 但是,如果您需要这样做,您的代码可能不够优雅。

The buffer size also affects performance: see Optimal buffer size for JSP's and autoflush property . 缓冲区大小也会影响性能:请参阅JSP和autoflush属性的最佳缓冲区大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM