Bookmark Topic Watch Topic
  • New Topic

'please wait' message while jsp is loading  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I have a jsp page that loads a lot of data from the database. Now when the page loads, it takes a lot of time for data to come back, so all I see is an empty page. Even title only says 'Microsoft Internet Explorer' w/o url. I saw somewhere couple of javascripts that use layers to display 'please wait' message, but it does not work in my case. I think there is a way of putting the whole java code in a thread, and make that thread stop and go until data comes back. While it stops a message is displayed. Has anybody seen this technique?
thanks,
Alex
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the solution I normally offer. It is only useful if the delay is due to processing on the servlet and is less useful when the problem is transfer times.
It starts by sending the data to a page that returns the data in a hidden form and prints the 'Please Wait' sign. The hidden form submits, and this is the page that is displayed until a repsonse is received.



 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
The problem with you specific situation is that you want to show something after the page starts loading but only until the page has completed loading.
This is more likely to be a HTML/Javascript (possibly DHTML) solution than a JSP-based solution.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Report post to moderator
You should use a refresh header to update the data live.
There's a good example here:
http://archive.coreservlets.com/coreservlets/PrimeNumbers.java

You want to set a flag from the db lookups.
if(!dsLookup.isDone()){
int seconds = 5;
response.setHeader("refresh", ""+seconds);
}
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Garrett Smith:
You should use a refresh header to update the data live.
There's a good example here:
http://archive.coreservlets.com/coreservlets/PrimeNumbers.java
You want to set a flag from the db lookups.
if(!dsLookup.isDone()){
int seconds = 5;
response.setHeader("refresh", ""+seconds);
}

but do you think it will show a wait screen or a loading screen!. I think it will only work for servelt based site and not people who use jsp.
unfortunately i'm using jsp for one set of process.
Any help ??
 
Sandeep. Oza
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dear Alex,
I have code - Java Script for say similar problem like you.. I am uploading one file of big size.. so there should be some indication that processing is going on... we are using this script and image upload_an.gif
Write it before closing Head
<script language=JavaScript>
<!-- Begin
function ProgressCreate() {
if (document.all) {// Internet Explorer
progress.className = 'show';
progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2);
} else if (document.layers) {// Netscape
document.progress.visibility = true;
document.progress.left = (window.innerWidth/2) - 100;
document.progress.top = pageYOffset+(window.innerHeight/2) - 40;
} else if (document.getElementById) {// Netscape 6+
document.getElementById("progress").className = 'show';
document.getElementById("progress").style.left = (window.innerWidth/2)- 100;
document.getElementById("progress").style.top = pageYOffset+(window.innerHeight/2) - 40;
}

}

function ProgressDestroy() {
if (document.all) {// Internet Explorer
progress.className = 'hide';
} else if (document.layers) {// Netscape
document.progress.visibility = false;
} else if (document.getElementById) {// Netscape 6+
document.getElementById("progress").className = 'hide';
}
}

// End -->
</script>
Write this before body tag but after closing Head tag:
<script language="JavaScript">
<!--

function progressBarDefAccess(){
document.upload.flag.value="access";
ProgressCreate();
}
-->
</script>
There is a form name= upload with a hidden field name= flag.
Write this script after closing form tag:
<SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<span id=\"progress\" class=\"hide\">");
document.write("<TABLE border=2 align=\"right\" bgcolor=\"#639C9C\">");
document.write("<TR><TD ALIGN=\"right\">");
document.write("<image src='/package/images/upload_an.gif' height='50' width='175'>");
document.write("</TD></TR>");
document.write("</TABLE>");
document.write("</span>");
ProgressDestroy();
-->
</script>
Call function ProgressCreate() onclicking submit button of the form( in my case). You can use flash gif image showing some kind of processing/progress bar...
Pl. let me know if it suits your need.. If you need image mail me on sandeepo@bsil.com
Good Day,
Sandeep Oza
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Sandeep. Oza:
Dear Alex,

Dear Sandeep,
I tried your code but its showing the progress image(gif) before i click the submit button for processing, i mean on the intial page itself. I think i'm not getting your logic.
Could you please post the full sample code for us.
Regards
Balaji
 
Sandeep. Oza
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dear Balaji,
Sorry man, I have forget to give you one more patch.
Pl. paste it after head tag befor script tag.:
<style>
.hide { position:absolute; visibility:hidden; }
.show { position:absolute; visibility:visible; }
</style>
It is used to hide the image and on clicking submit button, image appears till processing time then control goes to some new page as mentioned in <form action= "abc.jsp">
If still it not work's pl. let me know.
Good Day,
Sandeep Oza
[ November 07, 2002: Message edited by: Sandeep. Oza ]
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I found(stealed) a easy solution for this using javascript.
This will display a text "Loading..." untill the page is fully loaded.Its working for jsp perfectly.Haven't tested for Servlet yet, but for servlets there is proven solutions available already.
Please place this code before <html> start tag,

Place this code after closing the HTML tag</html>

have fun.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks everybody for you replies!
I tried JavaScript versions, but the thing is that my page is just sitting there waiting for data, and can't even display this 'waiting' layer. It only displays it ~30 sec. later after the page has loaded. I am not sure why this is happening, but let me explain quickly what I am doing. I have jsp page that takes a string as a parameter and sends this string to a class that searches datasbse for matching %searchString%, once it finds it, it returns a String[] of found results. This String[] is read by a JSP page that loops thru array and displays each element.
Now for some reason all of these operations take a really long time. That's why I wanted to create something that would display 'please wait' message. As I said JavaScript does not seem to work.
Balaji,
You said that there is a way of doing this task in servlets. Can you please explain how this is done with a possible code example.
thanks everybody,
Alex
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
The first thing I'd do in this case is talk to a DBA and see if there is anything they can do at their end to improve the query, or any other suggestions.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Report post to moderator

but do you think it will show a wait screen or a loading screen!. I think it will only work for servelt based site and not people who use jsp.
unfortunately i'm using jsp for one set of process.
Any help ??

I absolutely do think you should show a loading message! See how that example works. It is, I believe, the best solution for type of situation.
You just have to modify that code.
For example, where it says:
if (!isLastResult) {
response.setHeader("Refresh", "5");
}
you can say:

You could use a gif img (or a div) with an increasing width to make a progress bar.
Of course, you should use a servlet for this. If you work on optimizing the database calls, you may eliminate a good portion of delay, too.

Garrett
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Alex Kravets:
Thanks everybody for you replies!
Alex

Along with others suggestions!..
The javascript is working fine for me.
With reference to my previous javascript email,my jsp code looks somethng like this.

Check this thread to get the tutorial which shows how to show wait screen using servlet.
http://www.coderanch.com/t/355076/Servlets/java/Wait-Screen
here is the code snippet for you to use further.

Regards
Balaji
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Sandeep. Oza:
Dear Balaji,
Sorry man, I have forget to give you one more patch.If still it not work's pl. let me know.
Good Day,
Sandeep Oza
[ November 07, 2002: Message edited by: Sandeep. Oza ]


Thanks Sandeep,I found the other solution(that i posted) is easy for me and hope it will help you as well.
BYW i like your signature
Regards
Balaji
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok guys I think I found the best solution yet...for JSP that is. Here it is:
code:
-----
<%
if(session.getAttribute("wait") != null){
session.removeAttribute("wait");
%>
// this is you 'wait' block
<html>
<head><title>searching...</title>
<meta http-equiv='Refresh' content='0'>
<style type="text/css">
.wait{
font-family: arial;
font-size: 13px;
color: #ff0000;
font-weight: bold;
}
</style>
</head>
<body>
<table align="center" valign="middle">
<tr>
<td class="wait">
Please wait, menus are being searched...
<br>
<img src="bar.gif" border="0">
</td>
</tr>
<tr>
<td>
<img src="bar.gif" border="0">
</td>
</tr>
</table>
</body>
</html>
<%
}
else{
session.setAttribute("wait", new String());
%>
// this is where the 'real' page goes
<html>
<head><title>real page</title><head>
<body>
// content: db stuff...
</body>
</html>
This example works great in JSP.
Here is the thing though...in wait block I load this image called bar.gif that mimics progress bar, but when the wait block loads, the image does not appear at all. I tried to run queries that take 2 min or more, but no luck -- image does not load. I copied the wait block into a separate jsp page, and in there it works fine. Does anyone have any suggestions?
thanks,
Alex
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok, I found the problem. The reason why image did not load was because the refresh rate was set to '0'. So, every time page was reloaded, it started from an empty frame of animated bar.gif. If I channge refresh rate to let say 10, the image is loaded, but after 10 seconds, progress bar goes until the point where it left loading bar.gif before first 10 seconds were elapsed. Might be confusing. In any case, if bar.gif loads when I set refresh rate to 10, it kind of defeats the whole purpose of this technique becasuse the data might come back on the 31 second of the wait, but because refresh rate was set to 10, it has to wait another 9 seconds. Whatever, just thinking out loud.
Thanks for you help guys,
Alex
 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Alex Kravets,
The code given by you is working perfectly.But i would like to know that where can i get the bar.gif file so that i can use it in my application.Please help me.
Ravi
 
Rommel Sharma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Report post to moderator
I found two ways to show a "Please Wait..." message while processing goes on...they are quite similar the way they work. The sample code below should be descriptive enough...(JSP code for 'PleaseWaitMessage.jsp') [The code is a working code except the process.execute() method that denotes any processing you want to do]

//One way to do so,
<%
if ( session.getValue( "WAIT" ) == null )
{
session.putValue( "WAIT", "" );
out.println("Please Wait...Processing your request.");
out.println( "<script>location.href='PleaseWaitMessage.jsp';</script>" );
out.close();
}
else
{
session.removeValue( "WAIT" );
//Some Lengthy process...display some result of DB query
process.execute();
out.close();
}
%>
//Another way
<%
if ( session.getValue( "WAIT" ) == null )
{
out.println("<HTML>" );
out.println("<HEAD>" );
out.println("<TITLE>Please Wait...</TITLE>" );
out.println("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0\">" );
out.println( "</HEAD>" );
out.println("Please Wait...Processing your request.");
out.close();
}
else
{
session.removeValue( "WAIT" );
//Some Lengthy process...display some result of DB query
process.execute();
out.close();
}
%>
[ October 31, 2003: Message edited by: Rommel Sharma ]
 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Every Body,
I have JSP page which will fetch data from database.My requirement is that I need a Loading image which will show how many percentage has been complete and the other remain.How these thing is possible.Please help me..... ..Like XP os shows the percentage copying...or remaining time...


Ex:- Suppose it will fetch 100 records.....
the it will so 76 remains..like that


with regards
Mohan....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Adding your question to a 6-year-old thread isn't the best approach. I've closed this topic to allow youto open a new topic with your question.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!