• 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

Loading Time

 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My JSP page page takes some time to load, while loading, how can I show a message "loading, please wait"

How can I acheive this?

Thanks
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this.
 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Implement a progress bar in your page.
Look at this code , i got it from the net...hope it helps


start.jsp
---------
<% session.removeAttribute("task"); %>
<jsp:useBean id="task" scope="session" class="com.devsphere.articles.progressbar.TaskBean"/>
<% task.setRunning(true); %>
<% new Thread(task).start(); %>
<jsp:forward page="status.jsp"/>



status.jsp
----------

<jsp:useBean id="task" scope="session"
class="com.devsphere.articles.progressbar.TaskBean"/>
<HTML>
<HEAD>
<TITLE>JSP Progress Bar</TITLE>
<% if (task.isRunning()) { %>
<SCRIPT LANGUAGE="JavaScript">
setTimeout("location='status.jsp'", 1000);
</SCRIPT>
<% } %>
</HEAD>
<BODY>
<H1 ALIGN="CENTER">JSP Progress Bar</H1>
<H2 ALIGN="CENTER">
Result: <%= task.getResult() %><BR>
<% int percent = task.getPercent(); %>
<%= percent %>%
</H2>
<TABLE WIDTH="60%" ALIGN="CENTER"
BORDER=1 CELLPADDING=0 CELLSPACING=2>
<TR>
<% for (int i = 10; i <= percent; i += 10) { %>
<TD WIDTH="10%" BGCOLOR="#000080"> </TD>
<% } %>
<% for (int i = 100; i > percent; i -= 10) { %>
<TD WIDTH="10%"> </TD>
<% } %>
</TR>
</TABLE>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ALIGN="CENTER">
<% if (task.isRunning()) { %>
Running
<% } else { %>
<% if (task.isCompleted()) { %>
Completed
<% } else if (!task.isStarted()) { %>
Not Started
<% } else { %>
Stopped
<% } %>
<% } %>
</TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<BR>
<% if (task.isRunning()) { %>
<FORM METHOD="GET" ACTION="stop.jsp">
<INPUT TYPE="SUBMIT" VALUE="Stop">
</FORM>
<% } else { %>
<FORM METHOD="GET" ACTION="start.jsp">
<INPUT TYPE="SUBMIT" VALUE="Start">
</FORM>
<% } %>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

stop.jsp
--------

<jsp:useBean id="task" scope="session" class="com.devsphere.articles.progressbar.TaskBean"/>
<% task.setRunning(false); %>
<jsp:forward page="status.jsp"/>

com.devsphere.articles.progressbar.TaskBean(java file)
------------------------------------------------------

package com.devsphere.articles.progressbar;
import java.io.Serializable;
public class TaskBean implements Runnable, Serializable
{

public TaskBean()
{
counter = 0;
sum = 0;
started = false;
running = false;
sleep = 100;
}

protected void work()
{
try
{
Thread.sleep(sleep);
counter++;
sum += counter;
}
catch(InterruptedException interruptedexception)
{
setRunning(false);
}
}

public synchronized int getPercent()
{
return counter;
}

public synchronized boolean isStarted()
{
return started;
}

public synchronized boolean isCompleted()
{
return counter == 100;
}

public synchronized boolean isRunning()
{
return running;
}

public synchronized void setRunning(boolean flag)
{
running = flag;
if(flag)
started = true;
}

public synchronized Object getResult()
{
if(isCompleted())
return new Integer(sum);
else
return null;
}

public void run()
{
try
{
setRunning(true);
for(; isRunning() && !isCompleted(); work());
}
finally
{
setRunning(false);
}
}

private int counter;
private int sum;
private boolean started;
private boolean running;
private int sleep;
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Vinod NS",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic