简体   繁体   中英

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? What could happen if I do not modify them?

Anything generated by the JSP page is stored in a buffer. 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. Similarly you cannot add cookies to the response after the first flush.

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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