Ajax Introduction
Ajax is a technology that updates some webpages without the need to reload the entire webpage.
Ajax = Asynchronous JavaScript and XML.
Ajax is a technology used to create fast dynamic web pages.
By performing a small amount of data exchange with the server in the background, AJAX can implement asynchronous updates on webpages. This means that you can update a part of a webpage without reloading the entire webpage.
(From w3school)
This is the first time I used Ajax JSP source files, including Ajax. jsp and check. jsp.
<! -- Ajax. JSP --> <br/> <% @ page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <br/> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> ajax usage </title> <br/> <meta http-equiv = "Pragma" content = "no-Cache"> <br/> <meta http-equiv = "cache- control "content =" no-Cache "> <br/> <meta http-equiv =" expires "content =" 0 "> <br/> <meta http-equiv =" keywords "content =" keyword1, keyword2, keyword3 "> <br/> <meta http-equiv =" Description "content =" this is my page"> <Br/> <SCRIPT type = 'text/JavaScript '> <br/> var req; <br/> Function check () {<br/> var field = document. getelementbyid ("user"); <br/> var url = "check. JSP? Id = "+ escape (field. value); <br/> If (window. XMLHttpRequest) {<br/> Req = new XMLHttpRequest (); <br/>} else if (window. activexobject) {<br/> Req = new activexobject ("Microsoft. XMLHTTP "); <br/>}< br/> req. open ("get", URL, true, null, null); <br/> req. onreadystatechange = callback; <br/> req. send (null); <br/>}</P> <p> function callback () {<br/> If (req. readystate = 4) {<br/> If (req. status = 200) {<br/> document. getelementbyid ("check "). innerhtml = req. responsetext; <br/>}< br/> </SCRIPT> <br/> </pead> </P> <p> <body> <br/> <form> <br/> <Table align = 'center'> <br/> <tr> <br/> <TD> User Name </TD> <br/> <TD> <input type = 'text' id = 'user' onblur = 'check () '/> </TD> <br/> <TD id = 'check'> </TD> <br/> </tr> <br/> </table> <br/> </form> <br/> </body> <br/> </ptml> <br/>
Check. jsp
<% -- Check. JSP -- %> <br/> <% <br/> response. setcharacterencoding ("UTF-8"); <br/> response. setcontenttype ("text/XML"); <br/> response. setheader ("cache-control", "No-store"); <br/> response. setheader ("Pragma", "No-Cache"); <br/> response. setdateheader ("expires", 0); <br/> response. getwriter (). write ("OK"); <br/> %>