Example of XML file transmission via Ajax: For reference, ajax's xmlformat transmission .rar 0
In hjxxservlet:
Public class hjxxservlet extends httpservlet {
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Response. setcontenttype ("text/XML; charset = UTF-8 ");
// Obtain the date
String RQ = request. getparameter ("RQ ");
Khfxxtmanager = new khfxxtmanager ();
// Obtain call statistics
Hjtj = khfxxtmanager. gethjtj (RQ );
Document Doc = incluenthelper. createdocument ();
Doc. setxmlencoding ("UTF-8 ");
Element hjxxelt = Doc. addelement ("hjxx ");
Element hjtjelt = hjxxelt. addelement ("hjtj ");
// Today's quota
Hjtjelt. addelement ("jrhjl"). settext (string. valueof (hjtj. getyxth () + hjtj. getwxth ()));
// Valid call
Hjtjelt. addelement ("yxth"). settext (string. valueof (hjtj. getyxth ()));
// Invalid call
Hjtjelt. addelement ("wxth"). settext (string. valueof (hjtj. getwxth ()));
// Valid Call Success Rate
Hjtjelt. addelement ("yxthcgl"). settext (string. valueof (hjtj. getyxth ()/(hjtj. getyxth () + hjtj. getwxth ())));
String zt = NULL;
Try {
Long time = new simpledateformat ("yyyy-mm-dd"). parse (RQ). gettime ()-(1000*60*60*24 );
// Get yesterday
Zt = new simpledateformat ("yyyy-mm-dd"). Format (new date (time ));
} Catch (parseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
// Obtain call statistics from yesterday
Hjtj zthjtj = khfxxtmanager. gethjtj (zt );
// Effective call success rate compared with yesterday
Hjtjelt. addelement ("yxthcgltbzr "). settext (string. valueof (hjtj. getyxth ()/(hjtj. getyxth () + hjtj. getwxth ()-(zthjtj. getyxth ()/(zthjtj. getyxth () + zthjtj. getwxth ()))));
// Potential target customers
Hjtjelt. addelement ("qzyxkh"). settext (string. valueof (hjtj. getqzyxkh ()));
// Potential target customers compared with yesterday
Hjtjelt. addelement ("qzyxkhtbzr"). settext (string. valueof (hjtj. getqzyxkh ()-zthjtj. getqzyxkh ()));
// Obtain detailed information
List // Call details
Element hjmxelt = hjxxelt. addelement ("hjmx ");
For (iterator Hjmx = ITER. Next ();
Element hjjlelt = hjmxelt. addelement ("hjjl ");
// Original number
Hjlelt. addelement ("yshm"). settext (hjmx. getkhxx (). getdhhm ());
// Call status
Hjlelt. addelement ("hjqk"). settext (hjmx. gethjqk ());
// Name
Hjlelt. addelement ("XM"). settext (hjmx. getkhxx (). getxm ());
}
String xmlstring = Doc. asxml ();
Response. getwriter (). Print (xmlstring );
}
}
In index. jsp:
<SCRIPT>
Wdatepicker ({econt: 'did1', onpicked: function (DP ){
// Alert (DP. Cal. getdatestr ())
VaR XMLHTTP;
If (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
} Else if (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
VaR url = "Servlet/hjxxservlet? RQ = "+ dp. Cal. getdatestr () +" & timestamp = "+ new date (). gettime ();
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
// Alert (XMLHTTP. responsetext );
VaR Doc = XMLHTTP. responsexml;
// Today's quota
VaR jrhjl = Doc. getelementsbytagname ("jrhjl") [0]. firstchild. nodevalue;
// Valid call
VaR yxth = Doc. getelementsbytagname ("yxth") [0]. firstchild. nodevalue;
// Invalid call
VaR wxth = Doc. getelementsbytagname ("wxth") [0]. firstchild. nodevalue;
// Valid call successful
VaR yxthcgl = Doc. getelementsbytagname ("yxthcgl") [0]. firstchild. nodevalue;
// Effective call success rate compared with yesterday
VaR yxthcgltbzr = Doc. getelementsbytagname ("yxthcgltbzr") [0]. firstchild. nodevalue;
// Potential target customers
VaR qzyxkh = Doc. getelementsbytagname ("qzyxkh") [0]. firstchild. nodevalue;
// Potential target customers compared with yesterday
VaR qzyxkhtbzr = Doc. getelementsbytagname ("qzyxkhtbzr") [0]. firstchild. nodevalue;
Document. getelementbyid ("hjtj_div "). innerhtml = "<br/> outbound calls today:" + jrhjl + "<br/> valid calls:" + yxth + "Call <br/> invalid calls: "+ wxth +" Call <br/> effective call success rate: "+ yxthcgl +" % compared with yesterday: "+ yxthcgltbzr +" % <br/> Number of potential target customers: "+ qzyxkh +" bit compared with yesterday "+ qzyxkhtbzr +" % <br
/> ";
// Obtain details
VaR hjjl = Doc. getelementsbytagname ("hjjl ");
VaR S = "<Table border = '2' width = '750px; 'height = '300px 'cellspacing = '8px'> \ n ";
S + = "<tr align = 'center' bgcolor = '# cccccc'> \ n ";
S + = "<TH width = '000000'> original number </Th> \ n ";
S + = "<TH width = '000000'> call status </Th> \ n ";
S + = "<TH width = '000000'> name </Th> \ n ";
S + = "</tr> \ n ";
For (VAR I = 0; I VaR yshm = hjjl [I]. childnodes [0]. firstchild. nodevalue;
VaR hjqk = hjjl [I]. childnodes [1]. firstchild. nodevalue;
VaR XM = hjjl [I]. childnodes [2]. firstchild. nodevalue;
S + = "<tr bgcolor = '# cccccc' align = 'center'> \ n ";
S + = "<TD>" + yshm + "</TD> \ n"
S + = "<TD>" + hjqk + "</TD> \ n"
S + = "<TD>" + XM + "</TD> \ n"
S + = "</tr> \ n ";
}
S + = "</table> ";
Document. getelementbyid ("hjmx_div"). innerhtml = s;
} Else {
Alert ("request failed, error code =" + XMLHTTP. status );
}
}
};
XMLHTTP. Send (null );
}})
</SCRIPT>