c_sanjeev
asked on
Displaying intermediate page/image while processing request by jsp code
I have designed a create.jsp page to save data posted by info.htm but while processing this request it takes 5-40 secs.
Hence I want to display one page or image which will display message "Wait we are processing your request!"
I have tried this by adding html code to same "create.jsp" page but it is not displaying that rather it is displaying "Thank you" page after processing. To display Thank you page I am using "response.sendRedirect" in jsp code. I want to disaply intermediate page before this "Thank you" page
Thanks!
Sanjeev
Hence I want to display one page or image which will display message "Wait we are processing your request!"
I have tried this by adding html code to same "create.jsp" page but it is not displaying that rather it is displaying "Thank you" page after processing. To display Thank you page I am using "response.sendRedirect" in jsp code. I want to disaply intermediate page before this "Thank you" page
Thanks!
Sanjeev
One thing you might try is simply posting the data to the intermediate page, and then having the intermediate page re-post the exact same data. create.jsp would then process the data after the intermediate page re-posts it. Normally, this would just be an un-necessary step, but in this case, you *want* the intermediate page, so while the user waits, he/she sees the intermediate page. Hope that helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I had the same kind a problem a few weeks ago with a asp coded upload page i created.
What I did was place a session("uploaded")=false on the start of the processing page.
and on the end of that page a session("uploaded")=true.
Then I created a popup window with a meta refresh and then checking the state of the session("uploaded"). If it is false the popup window showed a "please wait..." text and if the state of the session was true then closed the popup.
It was a plain and easy solution to come up with. So maybe you can also.
What I did was place a session("uploaded")=false on the start of the processing page.
and on the end of that page a session("uploaded")=true.
Then I created a popup window with a meta refresh and then checking the state of the session("uploaded"). If it is false the popup window showed a "please wait..." text and if the state of the session was true then closed the popup.
It was a plain and easy solution to come up with. So maybe you can also.
You can handle it server-side in a very simple way (of course, this doesn't take browser-timeouts into account)
sleep.jsp:
-----------
Processing ...
<%
out.flush();
Thread.currentThread().sle ep(5000);
// do your stuff in stead of sleeping
%>
<hr>
Done
-----------
sleep.jsp:
-----------
Processing ...
<%
out.flush();
Thread.currentThread().sle
// do your stuff in stead of sleeping
%>
<hr>
Done
-----------
If you don't mind using javascript you can take Bart's idea one step further and dynamically send javascript to refresh the page once processing is complete. Do something like this:
<%@ page
%>
<HTML><HEAD><TITLE>Process ing your request</TITLE></HEAD><BOD Y>Processi ng...
<%
out.flush();
//do your stuff here
Thread.currentThread().sle ep(5000);
%>
<SCRIPT LANGUAGE="javascript">docu ment.locat ion="/done .jsp";</SC RIPT>
<%@ page
%>
<HTML><HEAD><TITLE>Process
<%
out.flush();
//do your stuff here
Thread.currentThread().sle
%>
<SCRIPT LANGUAGE="javascript">docu
What are you posting to? I had a problem where a servlet was taking a while to process something. I used x-multipart-encode to create a dynamic 'working' page that went to the solution when it was done.
Here's some html that does pretty much what you want - note that it belongs in a frame. The idea is that the target frame uses Javascript to display the 'waiting' message, launches the JSP action then uses the HTML returned from the JSP page to overwrite itself. Works well for me...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Application for something or other</TITLE>
<STYLE type="text/css">
P.cSpan {text-align:center; font-size:large; font-family: Times, serif; font-weight:bold }
</STYLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="styles.css">
<SCRIPT language="Javascript">
function doSpanText()
{
document.all.plsWait1.inne rText = "Please wait while your application is assessed.";
document.all.plsWait2.inne rText =" We may want to ask you some further questions.";
}
function extendSpanText()
{
document.all.plsWait1.inne rText += ".";
}
function doTimer()
{
window.setTimeout("doAsses s()", 2000);
}
function doWaitText()
{
window.setInterval("extend SpanText() ", 1000);
}
function doAssess()
{
document.all.plsWait1.inne rText = "Assessment in progress, please wait."
document.all.plsWait2.inne rText = " "
doWaitText();
parent.content.location.hr ef="/xyz/e ventHandle r?applicat ion_id=999 " +
"&event=ASSESS";
}
</SCRIPT>
</HEAD>
<BODY onLoad="doSpanText();doTim er()">
<div>
<br><br>
<center>Your application has been saved successfully.
</center>
<br>
<br>
<br>
<P class=cSpan>
<span id=plsWait1 ></span>
</P>
<P class=cSpan>
<span id=plsWait2 ></span>
</P>
</div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Application for something or other</TITLE>
<STYLE type="text/css">
P.cSpan {text-align:center; font-size:large; font-family: Times, serif; font-weight:bold }
</STYLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="styles.css">
<SCRIPT language="Javascript">
function doSpanText()
{
document.all.plsWait1.inne
document.all.plsWait2.inne
}
function extendSpanText()
{
document.all.plsWait1.inne
}
function doTimer()
{
window.setTimeout("doAsses
}
function doWaitText()
{
window.setInterval("extend
}
function doAssess()
{
document.all.plsWait1.inne
document.all.plsWait2.inne
doWaitText();
parent.content.location.hr
"&event=ASSESS";
}
</SCRIPT>
</HEAD>
<BODY onLoad="doSpanText();doTim
<div>
<br><br>
<center>Your application has been saved successfully.
</center>
<br>
<br>
<br>
<P class=cSpan>
<span id=plsWait1 ></span>
</P>
<P class=cSpan>
<span id=plsWait2 ></span>
</P>
</div>
</body>
</html>
You might idd do what COBOLdinosaur and BartRobeyns are suggesting:
a) if you submit the values (for processing) display a div with a flash movie or a gif displaying the wait-a-sec message
b) flush all the output to the client side
c) start processing your values
d) flush the rest of your page (after processing) to the client. This part of the page will contain some JS which will hide the div
So you might get something like this:
<%
if (request.getParameter("btn Submit") != null)
{
//display you wait message
%>
<div id="processing" style="position:absolute; top:100px; left:100px; z-index:10;display:none">
<img src="yourimage.gif">
<br />
wait we are processing your request...
</div>
<%
//flush output
out.flush();
//process all the values
// ...
// ...
// Send rest of html including the part where hide the div
%>
<script type="text/javascript">
function showLayer()
{
document.getElementById('p rocessing' ).style.di splay='blo ck';
document.forms[0].submit() ;
}
</script>
<%
}
%>
This might do the trick... (Credits to COBOLDinosaur, thanks for the HTMLCode ;o))
a) if you submit the values (for processing) display a div with a flash movie or a gif displaying the wait-a-sec message
b) flush all the output to the client side
c) start processing your values
d) flush the rest of your page (after processing) to the client. This part of the page will contain some JS which will hide the div
So you might get something like this:
<%
if (request.getParameter("btn
{
//display you wait message
%>
<div id="processing" style="position:absolute; top:100px; left:100px; z-index:10;display:none">
<img src="yourimage.gif">
<br />
wait we are processing your request...
</div>
<%
//flush output
out.flush();
//process all the values
// ...
// ...
// Send rest of html including the part where hide the div
%>
<script type="text/javascript">
function showLayer()
{
document.getElementById('p
document.forms[0].submit()
}
</script>
<%
}
%>
This might do the trick... (Credits to COBOLDinosaur, thanks for the HTMLCode ;o))
ASKER
Thanks for all Tips. I tried all and found 'COBOLdinosaur' solution more close to my problem.
Only change I am doing is instead of calling showLayer() from submit I am calling it from validation check procedure after complete check of all validations!
Thanks!
Sanjeev
Only change I am doing is instead of calling showLayer() from submit I am calling it from validation check procedure after complete check of all validations!
Thanks!
Sanjeev
ASKER
Handling this problem with 'COBOLDinosaur' solution is having one drawback of browser support.
Handling it at server side as per 'augustd' suggestion is more robust solution.
Thanks!
Sanjeev
Handling it at server side as per 'augustd' suggestion is more robust solution.
Thanks!
Sanjeev
Coool. Could this be my first points?
But maybe we should address why your processing takes 40 seconds in the first place?
But maybe we should address why your processing takes 40 seconds in the first place?
Are you familiar with ASP and javascript (not jsp)? Are you prepared to bump up the points to 500?
Regards
Peter