ajax

Ads
 

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

Ads









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 connect ajax with mysql without using php,asp or any other scripting language. please answer soon
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  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 with
AJAX with       Ajax resources, in a digg style, allows the user to register and addd his/her own links Read full Description
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 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
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
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
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 sample
Ajax sample  Hi, Where I can find the samples of Ajax program? Thanks   Hi, Please see Ajax Tutorials. Thanks
Ajax wiki
Ajax wiki  Hi, What is the url of wiki for Ajax tutorial. Thanks   Hi, Here is the link: Wikipedia Ajax url. Thanks
Ajax scripts
Ajax scripts  Hi, Tell me the names of Ajax Scripts that can be used for writing Ajax based applications? Thanks   Hi, Please see the Ajax Web Framework page. Thanks
Ajax training
Ajax training  Hi, I am looking for Ajax Training. From where I get training on Ajax? Thanks   Hi, Please visit Ajax Training url. Thanks
ajax example
Ajax Example Here is the list of few Ajax examples at RoseIndia.net. Ajax example Ajax example   Hi, Where can I find Ajax example program? Thanks   Hi, Get it at: Ajax Tutorials First Ajax
Ajax applications
Ajax applications  Hi, Where can I find Ajax applications? Thanks
Ajax json
Ajax json  Hi, How consume json file in ajax program? Thanks
Ajax grid
Ajax grid  Hi, How I can create ajax grid in my program? Thanks
Ajax tools
Ajax tools  Hi, What all ajax tools are available for programming? Thanks

Ads