JSP XMLHttpRequest Dynamic Non-refreshing and its Chinese garbled processing _jsp programming

Source: Internet
Author: User
1. Join in the <script type= "Text/javascript" in the page
XMLHTTP request with no refresh request
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 (' Cannot create XMLHTTP instance! ');
return false;
}
http_request.onreadystatechange=alertcontents;
Http_request.open ("POST", url,true);
Http_request.send (NULL);
}
2. Call--in the JS call request "Control is the url-mapping of the servlet configuration, the reference is the same as the generic URL"
Createrequest (' control ' + '? Cmd=listen ');
3. Handle "Chinese garbled problem" in servlet
PrintWriter out;
Response.setcontenttype ("Html/text");//This 5 line must be used for outputting Chinese, otherwise garbled
Response.setcharacterencoding ("UTF-8");
Response.setheader ("Cache-control", "No-cache");
Out=response.getwriter ();
Out.println ("Sorry, the system is busy, please try again later!") "); For the returned response result, the page is displayed directly with 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.