aspose file tools
The moose likes Servlets and the fly likes sending html to the browser whilst an intensive operation proceeds Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "sending html to the browser whilst an intensive operation proceeds" Watch "sending html to the browser whilst an intensive operation proceeds" New topic
Author

sending html to the browser whilst an intensive operation proceeds

dean tomlinson
Ranch Hand

Joined: Jan 31, 2002
Posts: 94
i would like to send some HTML to the browser that explains to the user that there data is being retrieved whilst my servlet retrieves their data.
currently i have 2 jsps and servlet in between.
the first jsp allows the user to enter some data and this is then submitted to the servlet, that retreives the request parameters and invokes various sources to gather the data. when the servlet finshes it forwards the request onto the second jsp which displays the retrieved data.
becasue the calls made by the servelt take around 30 seconds to complete the first jsp remains on the borwser all this time. what i was hoping to do was instantly display a new jsps that explains that there data is being retrieved, and for this to then request the servlet so it is this page that remains on the screen for 30 seconds and not the data entry page.
i tried doing this and putting the jsp forward tage at the bottom of the page, but this caused by wait page not to even display. i think i may be able to achieve the same end using some javascript on the wait page that onload, requests the servelt, but is there anyway i can do this elegantly in java / jsp code ?
thanks for your help - dean
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

no problem -- in a JSP the out object is of the type JspWriter (a buffered version of the Print Writer) -- so you can easily call out.flush(); to write the current output to the screen.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
dean tomlinson
Ranch Hand

Joined: Jan 31, 2002
Posts: 94
hi jessica, thanks a lot for your suggestion. however (from my understanding which isn't that great - so please correct me : ) ) you're idea would work if i wanted to just write say the first section of the display page, and then the rest once the data has been loaded.
i actually want to display a totally seperate page, whilst the data is loading, and once the data has loaded the request to be forwarded/redirected to the dispaly results page.
is this still possible ?
thanks a lot - dean
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

You can fake it a bit.

On your first page, which perhaps gathers the query elements, have this page submit to your wait page.

On the wait page, there is a hidden form, that will be populated by the data from your first page. This page has javascript onload that submits the form. The screen shouldn't clear until the "real" second page starts to come down.

So to your end user, it looks like they are submitting page one, they get the wait page, and then they get the second page.


haha.. i just read your entire post. summarize what i said above to "what you said".
[ May 01, 2002: Message edited by: Mike Curwen ]
dean tomlinson
Ranch Hand

Joined: Jan 31, 2002
Posts: 94
is it possible to start a new thread to handle the retrievel of the data. This time consuming process can then get underway, whilst the request is forwarded to the "Data Loading" jsp, that would have a javascript onload function that requests the final jsp. The final jsp, has a method at the top of the page, that blocks until the data retrieval has completed.
i just dont want the intermediary page to add to the time it takes for the user to see their results page.
with this approach there would be 1 additional thread for every concurrent user, so i would need to associate the session id with the thread and the data object instance it is populating.
it seems to be common to use additional threads when programming other java applications, but i haven't really heard much about it with gregards to java web development. is there any fundamental reasons why it is not mentioned in books etc ?
cheers, dean
Donal Lynch
Greenhorn

Joined: May 02, 2002
Posts: 15
Hi Dean,
A way of displaying multiple pages within one HTTP response is to use the multipart/x-mixed-replace content type. One site that uses this method is metacrawler.com, which displays a please-wait page while it submits a query to several search engines. This is what I use (at the Unix command line) to see the exact HTTP response:

I haven't used it myself so I don't know what the practical issues are. One thing that metacrawler does and that you might end up having to do is to send different responses to different types of browsers.
Good luck,
--
Donal
Here's some servlet code that demonstrates it in Netscape:
dean tomlinson
Ranch Hand

Joined: Jan 31, 2002
Posts: 94
cheers mate
so with your code benath, by specifying the content type in that way, every time you send the boundary string to the output stream the browser will act on this by clearing the screen so only the following output is diplayed.
i'll give it a go and let you know how i get on (ps it's home time for me now - and as its a public holiday in the UK on monday so i'll let you know on tuesday) - thanks again dean (have a great weekend)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending html to the browser whilst an intensive operation proceeds
 
Similar Threads
Avoiding the page to get refreshed
Parameters and Attributes
Multiple response for a request
populating bean values from jsp
applet servlet communication