ajax

ajax

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();
        }
%>
View Answers









Related Tutorials/Questions & Answers:
ajax
ajax  please describe the ajax
Ajax
Ajax  How to learn AJAX
Advertisements
Ajax
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example.ADS_TO_REPLACE_1 Instead of using PHP you can write your code in JSP. Thanks
ajax
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
ajax
ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager... me reg this. thanks KK   Combobox box using Ajax in JSP   i
Ajax
ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used,it would be a greater advantage.After fetching data
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
AJAX
ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO
ajax
ajax  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
AJAX - Ajax
AJAX  what is Ajax?WHAT IS THE USAGE OF IT?WHERE WE HAVE TO USE IT? GIVE ME EXPLANATION WITH EXAMPLE?  Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short is new web development technique used
AJAX - Ajax
AJAX  What is AJAX?how we will use it in java?what is the use of AJAX?give me example?   hi friend, Ajax plays a major role... characteristics have made it popular among the users to develop their site using Ajax
ajax - Ajax
ajax  Hi all, I want ajax validation in struts1.0 , I tried from many days but, i cound't find solution.. I am attaching my code here. struts... ("Your browser does not support Ajax HTTP"); return; } var s
ajax - Ajax
ajax  Dear Roseindia, I want small application using ajax validation in struts1 login. I tried from many days but, i coudn't get solution..Do some favour me..it's urgent. Thanqs for advance.   Hi
Ajax - Ajax
that : form1.html where all Ajax code is written : function showHint...){ alert ("Your browser does not support AJAX!"); return
AJAX - Ajax
("Your browser does not support AJAX!"); return; } var url="http://localhost
AJAX with
AJAX with       Ajax resources, in a digg style, allows the user to register and addd his/her own links Read full DescriptionADS_TO_REPLACE_1
What is ajax? - Ajax
What is ajax?  What is Ajax Programming? Can any one share the basic examples of it? thanks
Ajax Learner - Ajax
Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how should i proceed to learn Ajax. Thanks and Regards Ziaul Hauqe Siddique 
Ajax validation - Ajax
Ajax validation  how to validate a form using Ajax and php  ... you. Please visit for more informaton: http://www.roseindia.net/ajax/ajaxlogin/ajax-registration-program.shtml Thanks. Amardeep
Ajax Learner - Ajax
Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer from last one year. i have to use Ajax for my current project.pls guide me how should i proceed to learn Ajax. Thanks and Regards Ziaul Hauqe Siddique 
ajax basics - Ajax
ajax basics  i need ajax basics where can i find these........................ pls help me thanx in advance  Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short is new web development technique
ajax with php - Ajax
ajax with php  how to do autocomplete search using ajax wit php in object oriented format?.. data should me retrive from database.. plz the way?.. give some sample codings
Ajax form element - Ajax
Ajax form element  I have problem in passing a value into form feild using ajax. I want to get the value is as a parameter. Can some one help me plz
ajax in java - Ajax
ajax in java  Dear deepak sir, My page contain several control... will come "Caseno exist" Sir I am using Ajax first-time.Please help me.   Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short
Ajax type
Ajax type  hiii, Is Ajax a technology platform or is it an architectural style
2 - Ajax
Is Ajax Synchronous or Asynchronous?  Can ajax synchronous or asynchronous? Why
ajax synchronisation
ajax synchronisation  how to stop ajax execution for some specific time
Ajax tutorials
Ajax tutorials  Hi, Why I should learn Ajax? What is the use of Ajax and which is the best tutorial to learn Ajax? Thanks
Ajax example
Ajax example   Hi, Where can I find Ajax example program? Thanks   Hi, Get it at: Ajax Tutorials First Ajax Example Ajax Login Example Thanks
Ajax with jsp - Ajax
Ajax with jsp  multiple combo boxes with ajax in jsp?  Hi friend, I am sending you a link. I hope that, this link will help you. Please visit for more information. http://www.roseindia.net/jsp
ajax jsp - Ajax
ajax jsp  multiple combo with ajax using jsp?  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/comboSelect.shtml Thanks
ajax for sturts - Ajax
ajax for sturts  Hi, I am trying to connect to the struts action class using ajax but I am getting error(not able to call actionclass),but when i use servlets I can call easily. how to solv it? plz help me... thanks
displaying in ajax - Ajax
displaying in ajax  hi.. I have an Ajax page ,request gone to server... for the answer  Hi friend, Ajax example to solve the problem : "mainpage.jsp" Ajax Example function postRequest
any alternaive for AJAX - Ajax
developing a web application for my final year project. very one knows AJAX which... any... given below to create application in ajax...!");--------------Ajax Tutorialhttp://www.roseindia.net/ajax/  Yes
What is Ajax?
What is Ajax?  Hi, What is Ajax and what is use of Ajax in web programming? Thanks   Hi, Ajax stands for AJAX stands for Asynchronous... JavaScript and other technologies such as CSS and XML. Read more at What is Ajax
Learn Ajax
Learn Ajax  Hi, Give good links to learn ajax. What is the correct url at roseindia.net to learn Ajax? Thanks   Hi, If you are beginner in Ajax start learning from the index of Ajax tutorial. Start learning Ajax
Ajax samples
Ajax samples  Hi, Tell me the urls of ajax samples. I am trying to find good Ajax samples for learning Ajax programming quickly. As I have to work on an Ajax project in next few days. Thanks   Hi, Please see Ajax
Ajax in IE 7 - Ajax
Ajax in IE 7  My AJAX function does not update on IE 7. What can I do to solve this problem?  hai friend give cross browser...) { } } } This is the code u have to write in the AJAX based examples for cross Browser
Ajax user interface - Ajax
Ajax user interface  hello could anyone help my requirement is to design the database interaction using AJAX my requirement is a table... these all has to be do using JSP,AJAX,JDBC what exactly i needed
AJAX- Database not connected - Ajax
AJAX- Database not connected  Respected Sir/Madam, I am Ragavendran.R.. I am working with AJAX and Database.. Ajax code works fine but the database values are not retrieved if queried.. Instead, I could receive
code problem:ajax - Ajax
code problem:ajax  Hi,I am using ajax to populate a select box.for this I am writing out.write("ONE"); like that.it runs fine in firefox.bt not in IE.Can anyone help me out this... thanks
Table refresh with ajax - Ajax
Table refresh with ajax  I am using jsp/html in my code. Is it compulsory that i have to use a servlet to implement table refresh using ajax? Or jsp also would work? Rajatha

Ads