• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

PrintWriter flush() problem - flushing the output to the client

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am experiencing a problem with forwarding the request to the client.

Please see below what I am doing

public void doPost()(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

// Send the response to client.
forwardToJsp(xmlResponse, request, response);

// Log the performance statistics into database.
bd.logStatistics(startTime, endTime, getServerVersion());

}

private void forwardToJsp(
String xml,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

request.setAttribute("ImsResponse", xml);

RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/ImsOut.jsp");
rd.forward(request, response);

}

The above method forwardToJsp() calls ImsOut.jsp.

Code in ImsOut.jsp is

<%
response.setContentType("application/xml; charset=UTF-8");
String strResponse = (String)request.getAttribute("ImsResponse");
out.print(strResponse);
out.flush(); // Flush the content to client.

%>

What I observed is servlet is sending the response to the client only after completing the database call bd.logStatistics().

For some reason flush() is not working. This is happening if the client is Java http client or Microsoft ASP/COM client. It works fine if the client is a browser. Is this the expected behavior? or Is it a bug in IBM servlet engine?

This problem is occurring in WSAD and shared WAS servers. Is there any way to make the servlet send the response to the Java http or MS COM client before completing the database call? Your help is greatly appreciated.

Note: For a reason the method call order is in that way in doPost(). Program has to work calling both methods one AFTER another.
[ September 27, 2005: Message edited by: Nagesh Rachakonda ]
 
Nagesh Rachakonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Moderator,

Would you please take a minute in helping me out?

Appreciate your time.

Thanks
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic