aspose file tools*
The moose likes JSP and the fly likes Loading Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Loading Time" Watch "Loading Time" New topic
Author

Loading Time

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
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


Never take anything for granted because you never know when you will lose it
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Check this.


My blood is tested +ve for Java.
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
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;
}


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading Time