Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to send httpServletResponse in several chunked message?

807591Feb 26 2008 — edited Mar 1 2008
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2008
Added on Feb 26 2008
7 comments
4,027 views