Method for regularly refreshing Jquery, Ajax, and Struts2

Source: Internet
Author: User

Step 1: import the jquery plugin Copy codeThe Code is as follows: <script type = "text/javascript" src = "js/easyui/jquery-1.8.0.min.js"> </script>

Step 2: add the information display area in <body> </body>.Copy codeThe Code is as follows: <label id = "context"> </label>

Step 3: Add JS Code to the pageCopy codeThe Code is as follows: <script type = "text/javascript">
SetInterval ("Push ()", 1000*60 );
Function Push (){
$. Ajax ({
Type: "POST ",
Url: encodeURI ("crmMaintenance/crmAirpolicyAction-takeAllMonitor.action "),
Success: function (data ){
$ ('# Context'). text (data );
}
});}
</Script>

Step 4: Process requests in Struts2Copy codeThe Code is as follows: public void takeAllMonitor (){
Try {
HttpServletResponse response = ServletActionContext. getResponse ();
PrintWriter out;
Out = response. getWriter ();
Response. setCharacterEncoding ("UTF-8 ");
//... Insert business logic
Out. print ("Synchronous ...");
Out. close ();
} Catch (IOException e ){
E. printStackTrace ();
}
}

By now, you can regularly refresh the page, but there is still a problem, that is, out. when print ("") has Chinese characters, garbled characters may occur. If any hero knows how to handle the problem, he may wish to give some advice.

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.