I am facing following problem,
I am using ajax to get the data continousely without refreshing. Here i have devided a web page into 3 parts(top,left and right) using table in jsp. On the left part i am displaying some links. whenever user clicks on this link the output must be displayed on the right part. Here am using tag to display the output.Whenever user clicks on the link, am calling another jsp(two.jsp) which is responsible to get the new data from the server using javascript. Here every time it's giving '1' only. I am unable to solv this problem. I don't know why it is giving ready state as 1 every time. I am new to ajax.Please help me in resolving this problem.
Following is my code. - split.jsp
<html> <head> <script type="text/javascript" language="javascript"> var xmlHttp function postRequest() { if (typeof XMLHttpRequest != "undefined"){ xmlHttp= new XMLHttpRequest(); }else if (window.ActiveXObject){ xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlHttp==null){ alert ("Browser does not support XMLHTTP Request") return } var url="/AutoDialer/two.jsp"; xmlHttp.onreadystatechange = stateChange; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function stateChange(){ var readyState=xmlHttp.readyState; alert(readyState); if (readyState==4 || readyState=="complete"){ document.getElementById("display").innerHTML=xmlHttp.responseText; }else{ alert("else"); } } function send(){ setInterval(postRequest(),3000); } </script> <style type="text/css"> .voice{ text-decoration: blink; font-size: 50; font-family: serif; font: bold; color: blue; text-align: left; } .welcome{ color: pink; font-family: serif; font-size: 20; font-style: normal; font-weight: bold; } .headings{ font: bold; font-family: fantasy; font-size: 15; color: black; font-weight: bold; text-align: center; background-color: #6c6c6c; } .hyper{ text-decoration: none; color: black; } </style> </head> <body topmargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0"> <table width="100%" height="100%" border="5" cellpadding="0" cellspacing="0"> <tr height="20%"><td colspan="3"><span class="voice">VoiceNet Reports</span></td><td align="right"><img height="100%" width="70%" src="/AutoDialer/tatalogo.jpg"/></td></tr> <tr height="5%" bgcolor="red"><td colspan="2"><span class="welcome">Welcome:admin</span></td><td align="center"><div>Dynamic</div></td><td><a href="/AutoDialer/logout.jsp">logout</a></td></tr> <tr height=""> <td valign="top"> <table align="left" cellpadding="0" cellspacing="0"> <tr> <td><span class="headings">Pro-active Contact Reports</span> <br/>Â Â RealTime <ul> <li><a href=""><span class="hyper">Call Classification Report</span></a></li> <li><a href=""><span class="hyper">Campaign Performance Report</span></a></li> <li><a href="" onclick="send();"><span class="hyper">On Call Report</span></a></li> </ul> Â Â Historical <ul> <li><a href=""><span class="hyper">Campaign Performance Report</span></a></li> <li><a href=""><span class="hyper">Call Classification Report</span></a></li> <li><a href=""><span class="hyper">Call Detail Report</span></a></li> <li><a href=""><span class="hyper">List Penetration Report</span></a></li> </ul> </td> </tr> <tr> <td><span class="headings">CBM Reports</span> <br/>Â Â RealTime <ul> <li><a href=""><span class="hyper">On Call Report</span></a></li> <li><a href=""><span class="hyper">Call Back Performance</span></a></li> <li><a href=""><span class="hyper">Call Classification Report</span></a></li> </ul> Â Â Historical <ul> <li><a href=""><span class="hyper">Campaign Performance Report</span></a></li> <li><a href=""><span class="hyper">Call Classification Report</span></a></li> <li><a href=""><span class="hyper">Call Detail Report</span></a></li> </ul> </td> </tr> <tr><td><span class="headings">Galvanizer Reports</span> <ul> <li><a href=""><span class="hyper">Galvanizer Feeder Report</span></a></li> </ul> </td></tr> </table> </td> <td> <div id="display"></div> </td> </tr> <tr><td></td></tr> <tr><td></td></tr> </table> </body> </html> - two.jsp <%@ page import="java.util.*,com.tbss.*,com.timesten.jdbc.*,java.sql.*,java.util.*,java.text.*"%> <%@page import="java.util.Date"%> <% System.out.println("two.jsp"); String buffer=""; String id=request.getParameter("id"); buffer+="<div id='display' style='text-align: center;'><table border=1 cellpadding=0 cellspacing=0><tr bgcolor='#F08080'><th>COMPAIGN_ID</th><th>RECORD_ID</th><th>SESSION_ID</th><th>CONNECTEDPHONE</th><th>SESSION_DURATION</th></tr>"; TimesTenConnection ttcon=null; TimesTenDataSource ttds=null; Statement stmt=null; Statement stmtDelete=null; ResultSet rset=null; java.util.Date start=null; java.util.Date end=null; long s=0,e=0; Long old=new Long(0); Long cur=new Long(0); long dif=0; Set<Long> set=new HashSet<Long>(); String dateDisplay=null; DateFormat dbFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); try { ttds = new TimesTenDataSource(); ttds.setUrl("jdbc:timesten:client:dsn=ttc1;UID=ttsa;PWD=abc123"); ttcon = (TimesTenConnection) ttds.getConnection(); stmt = ttcon.createStatement(); stmtDelete=ttcon.createStatement(); java.util.Date after5Minutes=new java.util.Date(); long currentTimeInMilliSecords=after5Minutes.getTime(); Timestamp currentTimestamp=new Timestamp(currentTimeInMilliSecords); currentTimeInMilliSecords=currentTimeInMilliSecords-2*60*1000; java.util.Date before5Minutes=new java.util.Date(currentTimeInMilliSecords); String after5MinutesString=dbFormat.format(after5Minutes); String before5MinutesString=dbFormat.format(before5Minutes); rset=stmt.executeQuery("select * from rt_channels where START_TIME between '"+before5MinutesString+"' and '"+after5MinutesString+"'");//Retreiving the records which are inserted with in last 5 minutes int x=0; String bc=null; while(rset.next()) { Timestamp current=rset.getTimestamp("START_TIME"); long cPhone=rset.getLong("CONNECTEDPHONE"); if(x%2==0) bc="#FFEFD5"; else bc="#FAFAD2"; Timestamp prDate=(Timestamp)application.getAttribute(cPhone+""); cur=current.getTime(); if(prDate==null){//New number dateDisplay=current.toString(); application.setAttribute(cPhone+"",current); } else{//Old number old=prDate.getTime(); dif=cur-old; if(dif>2*60*1000l||dif<0){ rset.next(); application.removeAttribute(""+cPhone); stmtDelete.executeUpdate("delete from RT_CHANNELS where CONNECTEDPHONE="+cPhone);//Deleting the record. continue; }else{ String minutes=null; String seconds=null;//modifying from long milliSeconds=0,minutesLong=0,secondsLong; if(dif>=60*1000){ minutesLong=dif/(60*1000); milliSeconds=dif%(60*1000); secondsLong=milliSeconds/1000; if(secondsLong<10) seconds="0"+secondsLong; else seconds=secondsLong+""; if(minutesLong<10){ minutes="0"+minutesLong; }else{ minutes=""+minutesLong; } }else if(dif<60*1000){ minutes="00"; secondsLong=dif/1000; if(secondsLong<10) seconds="0"+secondsLong; else seconds=secondsLong+""; }else { minutes="00"; seconds="00"; } dateDisplay=minutes+":"+seconds;//modifying to } } if(x>9) break; buffer+="<tr bgcolor='"+bc+"'><td>"+rset.getLong("CAMPAIGN_ID")+"</td><td>"+rset.getLong("RECORD_ID")+"</td><td>"+rset.getString("SESSION_ID")+"</td><td>"+rset.getLong("CONNECTEDPHONE")+"</td><td>"+dateDisplay+"</td></tr>"; x++; } buffer+="</div>"; if(x==0) buffer="<b>Records not found</b>"; response.getWriter().println(buffer); }catch(SQLException ex){ ex.printStackTrace(); } finally{ rset.close(); stmt.close(); ttcon.close(); } %>