Ajax implementation of asynchronous loading page, the realization of real-time information updates

Source: Internet
Author: User
Tags tld

Three steps to achieve this function:

1, the mother page:

<%@ page language= "java" pageencoding= "UTF-8"%>
<%@ taglib uri= "/web-inf/config/struts-bean.tld" prefix= "Bean"%>
<%@ taglib uri= "/web-inf/config/struts-html.tld" prefix= "html"%>
<%@ taglib uri= "/web-inf/config/struts-logic.tld" prefix= "logic"%>
<%@ taglib uri= "/web-inf/config/ajj-html.tld" prefix= "ahtml"%>
<% @taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
<%@ page iselignored= "false"%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<link href= "Csslib/style_exammanager.css" rel= "stylesheet" type= "Text/css"/>
<script src= "Js/jquery.js" type= "Text/javascript" charset= "gb2312" > </script>
<script language= "javascript" type= "Text/javascript" >
SetInterval (show,120000), execute the Show method regularly, and refresh the examination information in real time
$ (document). Ready (function () {
Show ();
});
Function Show () {
$ ("#table_out"). HTML ("Information loading ...");
$.post ("Exammanager.do",
{
Operation: "Showexam"
},
function (data) {//The data returned here is a page (this page is a table, excluding the body, etc.)
$ ("#table_out"). HTML (data)//To embed the return page in the div of the current page
}
);
}
</script>

<body bgcolor= "Transparent" >
<div id= "right_table" class= "Float_left" >
<table border= "0" cellspacing= "0" cellpadding= "0" class= "width_95" >
<tr>
&LT;TD width= "9" ></td>
&LT;TD class= "Bg_topright" ></td>
</tr>
</table>
<div id= "Table_out" class= "width_95" >

</div>
<table border= "0" cellspacing= "0" cellpadding= "0" class= "width_95" style= "font-size:13px"; >
<tr>
&LT;TD width= "9" ></td>"
&LT;TD valign= "Middle" class= "bg_bottomright" ><div id= "page" class= "Algin_right" >
</div></td>
</tr>
</table>
</div>

</body>

===================================

2, the background action method:

=====================================

Public Actionforward Showexam (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {

List list=service.getrealtimeexamimformation ();
Request.setattribute ("list", list);
Return Mapping.findforward ("showtest_table");
}

===========================

3. Ajax returned Subpages (showtest_table.jsp):

===========================================

<%@ page language= "java" pageencoding= "UTF-8"%>
<%@ taglib uri= "/web-inf/config/struts-bean.tld" prefix= "Bean"%>
<%@ taglib uri= "/web-inf/config/struts-html.tld" prefix= "html"%>
<%@ taglib uri= "/web-inf/config/struts-logic.tld" prefix= "logic"%>
<%@ taglib uri= "/web-inf/config/ajj-html.tld" prefix= "ahtml"%>
<% @taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
<%@ page iselignored= "false"%>

<table style= "font-size:13px" width= "100%" border= "0" cellpadding= "0" cellspacing= "0" class= "border_1px" >
<tr>
<th><div class= "title_th" > Contact way </div><div class= "Title_line float_right" >|</div>< /th>
<th><div class= "title_th" > Name </div><div class= "Title_line float_right" >|</div></ Th>
<th><div class= "title_th" > Gender </div><div class= "Title_line float_right" >|</div></ Th>
<th><div class= "title_th" > ID number </div><div class= "Title_line float_right" >|</div> </th>
<th><div class= "title_th" > Admission number </div><div class= "Title_line float_right" >|</div> </th>
<th><div class= "title_th" > Exam time </div><div class= "Title_line float_right" >|</div>< /th>
<th><div class= "title_th" > Examination status </div><div class= "Title_line float_right" >|</div>< /th>
</tr>
<logic:present name= "List" >
<logic:iterate id= "list" indexid= "index" name= "list" >
<tr onmouseover= "This.classname= ' bg_over ';" onmouseout= "this.classname= ' bg_out ';" >
<td>
<c:if test= "${list.lxdh006==" | | List.lxdh006==null} ">
No contact phone
</c:if>

<ahtml:write name= "list" property= "lxdh006" type= "Lxdh"/>
</td>
<td>
<ahtml:write name= "list" property= "xm006" type= "XM"/>
</td>
<td>
<ahtml:write name= "list" property= "xb006" type= "XB"/>
</td>
<td>
${LIST.SFZHM006}
</td>
<td>
<ahtml:write name= "list" property= "kswyh007" type= "Kswyh"/>
</td>
<td>
<bean:write name= "list" property= "kssj059" format= "Yyyy-mm-dd HH:mm:ss"/>
</td>
<td>
<c:if test= "${list.jj059== ' 1 '}" >
Have handed in the papers
</c:if>
<c:if test= "${list.jj059== ' 2 '}" >
${list.zwapid059}
</c:if>
<c:if test= "${list.jj059== ' 0 '}" >
<font color= "Red" > </font>
</c:if>
</td>
</tr>
</logic:iterate>
</logic:present>
</table>

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.