Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


suresh anugandula
ajax
0 Answer(s)      3 years and 7 months ago
Posted in : 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();
        }
%>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Ajax
Ajax  How to learn AJAX
ajax
ajax  please describe the 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. 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
in a tabular form. Same for >33kv We can use ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used
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 Description
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 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
Advertisements
 

 

 

DMCA.com