Ajax and JSP combination for domain name query

Source: Internet
Author: User
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

<
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.