how to send httpServletResponse in several chunked message?
807591Feb 26 2008 — edited Mar 1 2008Hi all,
tomcat6.0, jdk5.0.
I need implement a servlet which uses some very long string as the response to POST request.
So I hope to divide the long string into several chunked http response messages instead of one huge response message. I tried below method:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
StringBuffer buf = new StringBuffer();
while(i<1000){
buf.append("some words");
}
String encoding = request.getCharacterEncoding();
response.setCharacterEncoding(encoding);
response.setStatus(200);
response.addDateHeader("Date",System.currentTimeMillis());
response.addHeader("Transfer-Encoding","chunked");
response.getOutputStream().write(buf.toString().getBytes());
......
}
But it failed. Client can't understand the response from the server.
Could anyone tell me what's the right way to implement chunked http servlet response?
Thanks a lot.
Rare
Edited by: hi-wanghan on Feb 26, 2008 5:08 PM