is it possible to open a new window from a servlet?
Actually i want to show a message "please wait..." in new window while servlet is doing some processing !
I have the code to display the "please wait message..." on the screen it self ...but the problem is that, my servlet is used for reading a file(doc,pdf,xls,text,html) from server. so if i display the message in servlet page itself like below -
so if i used the above code, the message gets displayed on the page. but the window should get closed automatically when the xls/doc file is open.
After the response text is sent back to the client, there's nothing you can do with it. So basically, once you close the PrintWriter instance, the response body is sent back to the client while you keep working with the OutputStream associated with the response. When you close the stream, you can't do anything about the page's display content.
Personally I don't think it's wise to work on both the PrintWriter and OutputStream associated with a HTTPServletResponse instance. More often than not, one gets to bump into an IllegalStateException.
Interesting solution Arnivan, however I am not sure about the implementation of it - when you reset the location.href are you appending all the form values and the submitting the form from the new page? Presumably with the entire form being hidden on the new page.
Personally I would submit the form as normal, and have the receiving servlet pass off the majority of the work to a pool of worker threads. The servlet is then free to return almost instantly to a screen that says "please wait". This new screen would then spawn an Ajax request to get the real response from the server once the worker thread completed.
Yes Andrew, it works although it sounds a bit strange. location.href simply changes the display page and doesn't submit the form. A snippet like this -
will display the HTML page while submitting the form to the servlet. When the servlet sends back its response, the browser will refresh with the servlet's content. I think the only limiting factor about this is that the time taken by the servlet to send back the response > time taken for moving to the HTML page [which usually is the case].
author and jackaroo
but my problem is xls,pdf reports have to be open in their native application and our code and property of IE does this. so if they open in microsoft applications and if we have applied something like the approaches i mentioend in my post and the approaches that you folks are suggesting then the jsp which has opened the servlet to read the file, would remain open as it is and we want to close the jsp/servlet page when the report is openned.
author and jackaroo
You could have a secondary servlet tracking whether the report has been sent or not
Use Anirvan's suggestion to get the temporary page displaying, and have that page generate an Ajax request every 'x' seconds to the secondary servlet to check the status - if the report has been sent then the tab can close itself.