简体   繁体   中英

Regarding http response appending extra characters in ie

I am facing the problem with http response in IE browser in chrome it works fine. When I am setting HttpResponse as:

response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.getWrite().write("xyz");
response.getWrite().flush();
response.getWrite().close();

The response in browser displayed is like: 3 xyz0 numerical character is appended at the begening and end of the string.

How to remove extra characters 3 and 0 , issue exists only in IE

Try setting the Content-length header of the response. Seems like your servlet container are sending the response data as chunked , the characters "3" (the number of the octects of data in the chunk expressed in hexadecimal value) and "0" (last chunk) are markers for the received data when is no content-length header present in the response, try this

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();

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