• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to give delay in JSP ?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
In JSP, we have a bean which does a lot of computation & takes time substantially.
So here instead of letting user to wait for page to come up, we want to give 'wait'
message over page. & after computation is done, then need to display result.
The problem is, we cant give delay message, since HTML will be rendered only when,
processing with page is done.
Its like you know in our standalone applications for spalsh screen where at the time
of launch of program we purposefully give delay & proceed with further execution.
So the same way in HTTP scenario, does anyone have any idea.
Eagerly waiting for ur replies !
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very naive solution that could work. Here goes ...

Suppose you have a 2 page web application. The 1st page is a normal html page containing a form and the other page is generated dynamically by JSP (page2.jsp)
Thus, to create a delay, introduce a new JSP/Servlet generated page, that does nothing but, stores the results in the session and starts off the processing in a Thread, generates a unique ID for this request (session ID should be fine) and returns including a
Thus, the splash page is displayed for 10 seconds in the above case and then the browser makes another request to the jsp page, page2.jsp with the CODE.
In the jsp page, check if the Thread has completed processing (you need a server side communication mechanism for this which is described later)
If so, get the data and do the needful.
If not, Wait till the data is ready (synchronization). Thus, the browser will be still showing the splash while trying to connect to the new page.
Server Side Communication
As you will be spawning threads to do the work, you need to provide a means for the Threads to communicate completion of work. There are various ways you can do that. The simplest way is a Message Board, where each thread has its own space.
When the server hands work to the thread, put a mark in the thread's space (say FALSE).
When the worker finishes the work, it erases the mark in its space (TRUE) and so on...
Disadvantages :
I know there could be a lot of threads spawned at the server side that would affect server performance. But, if the expected server load is not too high, a thread pool could be used.
I hope this helps.
Ashwin.

[This message has been edited by Ashwin Desai (edited March 20, 2001).]
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done this using javascript to. When the user does whatever is necessary to start the process- ie clicking a button or clicking on a link, take him to a page that says "processing". Now, on that HTML page, create a dummy form, with the action set to the page or servlet that does the actual processing. The "processing" page will stay up until the other page finishes all the processing and is ultimately displayed.
<dummy processing page follows>
...
PROCESSING
...
<form name="dummyForm" action="LongProcess.jsp" method="post">
<script>
document.dummyForm.submit();
</script>
</form>

HTH
Brian
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brain,
You trick looks neat! I like it!
regds
maha anna
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is this the flow of the problem?
1) page1.jsp loads
2) user clicks on something to go to page2.jsp
3) page1.jsp stays in the browser until page2.jsp does all it's stuff and then page2.jsp loads completely.
if so, make page1.jsp like this:
<html>
<head>
<script>
<!--
function showWaitingMessage() {
// IE5 and NN6
if (document.getElementById) {
document.getElementById("waitingpart").style.visibility="visible";
document.getElementById("realpart").style.visibility="hidden";
}
// NN4
else if (document.layers) {
document.layers["waitingpart"].visibility = "visible";
document.layers["realpart"].visibility = "hidden";
}
// IE4
else {
document.all.waitingpart.style.visibility="visible";
document.all.realpart.style.visibility="hidden";
}
}
//-->
</script>
</head>
<body>
<div id="realpart" style="visibility:visible">
Your page1.jsp normal html and/or other jsp stuff goes in here.
and
so does:
<a href="page2.jsp" onClick="showWaitingMessage()">
</div>
<div id="waitingpart" style="visibility:hidden">
Please stand by while the data is gathered etc...
</div>
</body>
</html>
BUT...
if page1.jsp is a form and the action is page2.jsp, change it to:

<form name="myform" action="page2.jsp">
...your form stuff here...
<input type="Button" name="thesubmitbutton" value="Submit" onClick="showWaitingMessage();window.document.myform.submit()">
</form>
or if it's the case that half of page2.jsp begins loading and then stalls while you perform the other stuff, let me know and I can try to help with that case instead. :-)
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have similar situation (as above)but bit different any help is appreciated.
1)login.html
2)validation.jsp(redirects to error.jsp or result.jsp)
3)result.jsp and error.jsp
when user enters his login info and submits it goes to validation.jsp there bean is giving validation info and based on that validation.jsp is forwarding to appropriate pages.
validation page does not display anything.
if he is valid user then other bean fetching more info and preparing result.jsp(approx after 11sec) and then result.jsp is diplayed.
Can some one help me to display some processing page in between.
Thanks
Vetri selvi
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what i would have done but may not be the best.
your login.html call the validation.jsp on submit. Your validation.jsp calls a validation bean which contains a method which will return "true" or "false" depending on the success or failure of your validation. Now check the return value of that method inside your jsp. If it returns faLse throw an exception which will automatically take you to the error jsp page, if you have one defined in your jsp(or redirect it to error.jsp explicitly) else use <jsp:forward> tag to go to the next success page

Hope this helps.
Ajan
[This message has been edited by Ajan Balakrishnan (edited March 23, 2001).]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"vetriselvi",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic