Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 关于在ie中附加额外字符的http响应_Java_Http - Fatal编程技术网

Java 关于在ie中附加额外字符的http响应

Java 关于在ie中附加额外字符的http响应,java,http,Java,Http,我面临的问题是IE浏览器中的http响应在chrome中工作正常。 当我将HttpResponse设置为: response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.getWrite().write("xyz"); response.getWrite().flush(); response.getWrite().close(); 浏览器中显示的响应如下所示: 3 xyz0 数字字

我面临的问题是IE浏览器中的http响应在chrome中工作正常。 当我将HttpResponse设置为:

response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.getWrite().write("xyz");
response.getWrite().flush();
response.getWrite().close();
浏览器中显示的响应如下所示: 3 xyz0 数字字符附加在字符串的开头和结尾

如何删除额外的字符3和0,问题只存在于IE中,请尝试设置响应的标题。看起来您的servlet容器正在发送响应数据,当响应中不存在
内容长度
头时,字符“3”(以十六进制值表示的数据块中的数据八位字节数)和“0”(最后一个数据块)是接收数据的标记,请尝试以下操作

String content = "xyz";
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setContentLength(content.getBytes().length);
response.getWriter().write(content);
response.getWriter().flush();
response.getWriter().close();

尝试编写有效的HTML。我们已经尝试了相同的设置内容长度,但仍然存在问题。请将IE收到的完整响应与标题和数据一起发布好吗?