Jquery Ajax Struts2 complete the timed refresh method
- 2020-06-07 05:09:49
- OfStack
Step 1: Import the jquery plug-in
Step 2: Yes < body > < /body > Where to add information to display
Step 3: Add the JS code to the page
Step 4: In Struts2, request processing takes place
At this point, you can regularly refresh the page, but there is still one problem, out. print("") when there is Chinese, there is a disorderly code problem, if any warrior knows how to deal with, also want to point 12.
<script type="text/javascript" src="js/easyui/jquery-1.8.0.min.js"></script>
Step 2: Yes < body > < /body > Where to add information to display
<label id="context"></label>
Step 3: Add the JS code to the page
<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: In Struts2, request processing takes place
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();
}
}
At this point, you can regularly refresh the page, but there is still one problem, out. print("") when there is Chinese, there is a disorderly code problem, if any warrior knows how to deal with, also want to point 12.