File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Multi part resonse from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Multi part resonse from servlet" Watch "Multi part resonse from servlet" New topic
Author

Multi part resonse from servlet

Shubhashis Dasgupta
Greenhorn

Joined: Jul 27, 2001
Posts: 9
My servlet is doing a long processing job and the request is getting timed out. Can anybody help me about this so that I can send multipart response and my request will not be timed out?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Shubhashis Dasgupta
Greenhorn

Joined: Jul 27, 2001
Posts: 9
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?
Aman Rustogi
Greenhorn

Joined: May 11, 2001
Posts: 22
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multi part resonse from servlet
 
Similar Threads
accessing tomcat default page
Doubt in Session Attributes (HFSJ)
How do I upload large files?
Doubt on a question in Listeners
Remote JDBC connection performance question