giri
giri

Reputation: 27199

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

Upvotes: 1

Views: 452

Answers (1)

vzamanillo
vzamanillo

Reputation: 10404

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

Upvotes: 3

Related Questions