- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Google 的 Appengine with Java 中,servlet:
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Writer w=resp.getWriter();
w.write("a");
resp.resetBuffer();
w=resp.getWriter();
w.write("b");
}
在开发服务器的响应中给出“ab”。通过阅读 Servlet Spec 2.5,我被期望只是“b”。
怎么了?
我正在 https://cloud.google.com/appengine/docs/java/requests 阅读文档.
我尝试了 resp.setBufferSize(8192) 和 getBufferSize() 但只得到 1。
appengine 版本:1.9.34,java 版本:openjdk 版本“1.8.0_66-internal”,ubuntu 14.10
最佳答案
这是 Java Servlet 规范(3.0 版)的内容:
"The
reset
method clears data in the buffer when the response is not committed. Headers and status codes set by the servlet prior to the reset call must be cleared as well. TheresetBuffer
method clears content in the buffer if the response is not committed without clearing the headers and status code.If the response is committed and the
reset
orresetBuffer
method is called, anIllegalStateException
must be thrown. The response and its associated buffer will be unchanged."
从表面上看,这表明 resetBuffer
应该清除 “a”
或抛出异常。
我想,您可以提出这样的论点,即字符在 Writer
中缓冲,而不是在响应缓冲区中缓冲,但 Servlet 规范没有做出任何此类区分。此外,这种对规范的解释会使 resetBuffer
变得毫无用处。
如果 Google AppEngine 确实按照您所说的方式运行,我会称之为错误。
关于java - HttpServletResponse.resetBuffer() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691900/
在 Google 的 Appengine with Java 中,servlet: @Override protected void doGet(HttpServletRequest req, Htt
我是一名优秀的程序员,十分优秀!