How can I close the output stream after a jsp has been included.
Posted
by stu
on Stack Overflow
See other posts from Stack Overflow
or by stu
Published on 2010-05-06T16:35:52Z
Indexed on
2010/05/06
16:38 UTC
Read the original article
Hit count: 149
I have a webpage that makes an ajax call to get some data. That data takes a long time to calculate, so what I did was the first ajax server call returns "loading..." and then the thread goes on to calculate the data and store it in a cache. meanwhile the client javascript checks back every few seconds with another ajax call to see if the cache has been loaded yet. Here's my problem, and it might not be a problem. After the initial ajax to the server call, I do a ...getServletContext().getRequestDispatcher(jsppath).include(request, response); then I use that thread to do the calculations. I don't mind tying up the webserver thread with this, but I want the browser to get the response and not wait for the server to close the socket. I can't tell if the server is closing the socket after the include, but I'm guessing it's not. So how can I forcibly close the stream after I've written out my response, before starting my long calculations?
I tried
o = response.getOutputStream();
o.close();
but I get an illegal state exception saying that the output stream has already been gotten (presumably by the jsp I'm including)
So my qestions:
1) is the webserver closing the socket (I'm guessing not, because you could always include another jsp)
2) if it is as I assume not closing the socket, how do I do that?
© Stack Overflow or respective owner