First, send the requested HTML file
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
var xmlhttpreq; Creates a XMLHttpRequest object function Createxmlhttprequest () {if window.
XMLHttpRequest) {//mozilla browser xmlhttpreq = new XMLHttpRequest (); else if (window.
ActiveXObject) {//IE browser try {xmlhttpreq = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {try {xmlhttpreq = new ActiveXObject ("Microsoft.XMLHTTP"); The catch (e) {}}}//Send request functions function SendRequest () {document.getElementById ("comments"). InnerHTML
= "is inquiring, please wait a moment ...";
Createxmlhttprequest ();
var Name=document.getelementbyid ("words"). Value;
var url = "domainquery1.jsp?words=" +name;
Xmlhttpreq.open ("Get", url, True); Xmlhttpreq.onreadystatechange = processresponse;//Specifies the response function xmlhttpreq.send (null); Send request//Process return information function ProcessResponse () {if (xmlhttpreq.readystate = = 4) {///Judge Object state if (XML
Httpreq.status = = 200) {//The information has been successfully returned to start processing information Display (); } else {//pageThe face is not normal window.alert ("the page you requested has an exception.)
");
}} function Display () {var msg=xmlhttpreq.responsetext;
document.getElementById (' comments '). value=msg; } </script>
<body bgcolor= #cccca3 >
Please enter the domain name: <input type= "text" value= "cctv.com" id= "words" name= "words" size= ">"
<input type= "Submit" value= "Query" id=submit1 name=submit1 onclick= "SendRequest ()" >
<textarea id= "Comments" name= "comments" ReadOnly rows=15 cols=76></textarea>
</body>
Second, processing AJAX request JSP file:
domainquery1.jsp
<%@ page import= "java.io.*"%>
<%@ page import= "java.util.*"%>
<%@ page import= "java.net.HttpURLConnection