Hi everyone
Plz reply..its urgent
I am trying to track progress of a database operation . and want to dislplay percentage progress on page asynchronously.

Process.jsp - In this i used javascript to call ajax function continuously which returns precentage progress.
My Code is :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp"><title>Untitled Document</title>
</head>
<jsp:useBean id="form1" scope="session" class="testing.HelloWorld"/>
<%
form1.check();
 %>
<body>

<script type="text/javascript">
var j=0;

function repeat()
{
var i=0;

while(i!=1)
{
i=getPercentage();
alert ("i = " + i);
}
}

function getPercentage()
{

var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
 	document.myForm.time.value=xmlhttp.responseText;
 	if(document.myForm.time.value=="100")
 	{
 	alert("final reached");
 	j=1;
 	}
  }
}


xmlhttp.open("GET","test.jsp",true);
xmlhttp.send(null);
alert ("j=" + j);
return j;
}
</script>

<form name="myForm">
Name: <input type="text" name="username"  />
Time: <input type="text" size=100 name="time" />
<button onclick="repeat()">Track Progress</button>
</form>

</body>
</html>

So that when user clicks on track progress button, It calls a repeat () function which continuously calls getPercentage() function and break when i=1 (Value returned by getPercentage is 1 when it is 100 %).

But it is not functioning properly.
can some one tell what is problem.

code of test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
Connection con;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://msachan.desktop.amazon.com:3306/lm_v2","root","ro0t");

Statement st = con.createStatement();
String query = "SELECT lm_start_id ,lm_current_id ,lm_end_id  FROM mirror_statuses WHERE mirror_status_id=256 ";
ResultSet rs= st.executeQuery(query);
String op;
PrintWriter out1 = response.getWriter();
int percent;
String percenttext=null;

while(rs.next())
{
int sid = rs.getInt(1);
int cid = rs.getInt(2);
int eid = rs.getInt(3);
percent = (cid-sid+1)*100/(eid-sid+1);
percenttext=percent+"";
System.out.println("sid=" + sid + "cid = " + cid + "eid = " + eid)
System.out.println("Percentage completion is : " + percenttext);
out1.write(percenttext);
}
out1.close();
con.close();
%>

This may be a JSP producing this javascript, the error is, seemingly, in the javascript, however, so the question is better asked in the javascript forum.

This article has been dead for over six months. Start a new discussion instead.