Iii. Task progress
The status. jsp page displays the execution status of the task to the user using an HTML progress bar. First, status. jsp uses the <jsp: useBean> tag to obtain the Bean object created on the start. jsp page:
<Jsp: useBean id = "task" scope = "session"
Class = "test. barBean. TaskBean"/>
To timely reflect the task execution progress, status. jsp will be automatically refreshed. The JavaScript code setTimeout ("location = status. jsp", 1000) refresh the page every 1000 milliseconds and Request status. jsp again without user intervention.
<HTML>
<HEAD>
<TITLE> JSP progress bar </TITLE>
<% If (task. isRunning () {%>
<Script language = "JavaScript">
SetTimeout ("location = status. jsp", 1000 );
</SCRIPT>
<% }%>
</HEAD>
<ODY>
The progress bar is actually an HTML table containing 10 units-each representing the overall 10% progress of the task.
<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"> & nbsp; </TD>
<% }%>
<% For (int I = 100; I> percent; I-= 10) {%>
<Td width = "10%"> & nbsp; </TD>
<% }%>
</TR>
</TABLE>
Task execution is in the following statuses: Execution in progress, completed, not started, and stopped:
<Table width = "100%" BORDER = 0 CELLPADDING = 0 CELLSPACING = 0>
<TR>
<Td align = "CENTER">
<% If (task. isRunning () {%>
Executing
<%} Else {%>
<% If (task. isCompleted () {%>
Complete
<%} Else if (! Task. isStarted () {%>
Not started
<%} Else {%>
Stopped
<% }%>
<% }%>
</TD>
</TR>