JSP XMLHttpRequest: dynamically refresh and process Chinese garbled characters

Source: Internet
Author: User

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 ().
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.