(1)first.html
<! Doctype HTML public "-// W3C // dtd html 4.01
Transitional // en "> <HTML> Id = "mailtable"> </div> <script
Language = "JavaScript"> var XMLHTTP = false; try {XMLHTTP = new activexobject ("msxml2.xmlhttp");} catch (e) {try {XMLHTTP = new activexobject ("Microsoft. XMLHTTP ") ;}catch (E2) {XMLHTTP = false ;}} if (! XMLHTTP & typeof
XMLHttpRequest! = 'Undefined') {XMLHTTP = new XMLHttpRequest ();} // defines table data var mail_list = new array (); function drawtable () {var table = "<Table border = \" 1 \ "width = \" 80% \"
Id = \ "Table1 \" cellspacing = \ "0 \"
Cellpadding = \ "0 \"> "; Table + =" <tr> <TD
Width = \ "20% \"> sender </TD> <TD
Width = \ "60% \"> title </TD> <TD
Width = \ "20% \"> sending time </TD> </tr> "; for (I = 0; I <mail_list.length; I ++) {table + = "<tr> <TD
Width = \ "20% \"> "+ mail_list [I]. Sender +" </TD> <TD
Width = \ "60% \"> "+ mail_list [I]. Title +" </TD> <TD
Width = \ "20% \"> "+ mail_list [I]. sendtime + "</TD> <tr>";} table + = "</table>" too many temporary Doc ument. getelementbyidx_x ("mailtable "). innerhtml = table;} // insert a data function into the table: addmail (ID, sender, title, sendtime) {var OBJ = new object (); obj. id = ID; obj. sender = sender; obj. title = title; obj. sendtime = sendtime; for (I = mail_list.length; I> 0; I --) {mail_list [I] = mail_list [I-1];} mail_list [0] = OBJ ;} // check whether emails on the server arrive at checkmail (); function checkmail (){ VaR url = "MailServer. JSP "; XMLHTTP. open ("Post", URL, false); XMLHTTP. onreadystatechange = analresponse; // send the request XMLHTTP. send (null); setTimeout ("checkmail ()", 5000);} function analresponse () {If (XMLHTTP. readystate = 4) {var response = XMLHTTP. responsetext; If (response. length> 1) {// parse the returned data, retrieve the sender, title, sending time, Update page // obtain idvar id = getstringfromdata (response, "ID "); vaR sender = getstringfromdata (response, "sender"); var Title = getstring Fromdata (response, "title"); var sendtime = getstringfromdata (response, "sendtime"); If (ID! = "") {// Add an addmail (ID, sender, title, sendtime) to the table data; // redraw the table drawtable (); // if the current browser is not the focus, the window will flash in the taskbar. focus () ;}}} function getstringfromdata (strin, tag) {var tag1 = "<" + tag + "> "; vaR tag2 = "</" + tag + ">"; var I1 = strin. indexof (tag1); If (I1 <0) Return ""; I1 + = tag1.length; var I2 = strin. indexof (tag2); If (I2 <0) Return ""; return strin. substring (I1, I2) ;}</SCRIPT> </body> Pageencoding = "gb18030" %> <% int x = math. ABS (new random (). nextint (10); system. out. println ("===========" + (New
Random (). nextint (10); If (X % 10 = 3) {string mail = "<mail>" +
"<ID>" + math. Abs (new random (). nextint () +
"</ID>" + "<sender> sender" + x + "</sender>" +
"<Title> simulate mail title" + new random (). nextint (1000) +
"</Title>" + "<sendtime>" + new
Date (). tolocalestring () + "</sendtime>" +
"</Mail>"; out. Print (Mail); system. Out. println (Mail) ;}%> real-time reminder email function; brushed with Ajax.