This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Web browsers don't work that way. The usual approach is to return a page that has automatic refresh turned on. Every few seconds it resends the request, polling the web server. When the web server has the data all ready for transmission, it sends the data instead of the "please wait" page. I like to further refine this by limiting the polling period to "X"-many minutes worth of polling, just so the user's browser doesn't somehow end up tying up the server polling mindlessly after the user has left for the day. If "X" has expired I put a "Click here to start checking again" button on the polling page.
An IDE is no substitute for an Intelligent Developer.
Joined: Jul 27, 2001
Thnx Tim. But the problem I am having is something different. My purpose is not to show a "wait" page, but to show some output data after some processing is done and in a regular manner. Let's say a database update(long duration) is done in a loop and after each iteration I need to send some output to the client. Then how can I implement that?
u can trying flushing out the data from ur output stream after each iteration, to immediatly display the contents on the browser [using out.flush()]. Besides if u r using a Query String to update data, u could try using a stored procedure to do the same which comparatively is much faster than ur plain SQL string.
Ooops. Just reread that. OK, the reason the browser times out is so the user doesn't get locked up is the server goes down. You HAVE to respond in a reasonable time, for the user's sake. If the process takes longer than that interval, you should pass it off to another (asynchronous) task on the server, THEN use the "wait" mechanism to keep the connection alive, and have the web server check the progress of the process server. The reason you need a "wait" page is that a web server CAN'T "push" output, only respond to requests, so you just keep sending requests until there's output available. In some cases, you may want to display that output incrementally, as it becomes available, in which case just pass it back as part of the "wait" page. Not the most beautiful solution in the world, I admit, but the only one I know of that works in the general http world.