1. Add <script type = "text/JavaScript">
// Xmlhttp request without refreshing new requests
Var http_request = false;
Function createRequest (url)
{
Http_request = false;
If (window. XMLHttpRequest) {// Mozilla, Safari ,...
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ('text/html ');
}
} Else if (window. ActiveXObject) {// IE
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Alert ('the XMLHTTP instance cannot be created! ');
Return false;
}
Http_request.onreadystatechange = alertContents;
Http_request.open ("POST", url, true );
Http_request.send (null );
}
2. Call -- call the request in js [CONTROL the url-mapping configured for servlet, passing parameters is the same as passing parameters in general URLs]
CreateRequest ('control' + '? Cmd = Listen ');
3. Handling [Chinese garbled characters] In servlet]
PrintWriter out;
Response. setContentType ("html/text"); // these five lines are required to output Chinese characters; otherwise, garbled characters
Response. setCharacterEncoding ("UTF-8 ");
Response. setHeader ("Cache-Control", "no-cache ");
Out = response. getWriter ();
Out. println ("sorry, the system is busy. Please try again later! "); // The returned response result is displayed on the page using alert ().