Using XMLHTTP in JSP for data interaction

Source: Internet
Author: User
Tags return string version domain
js|xml| Interactive | data
1. Client Submission Request

Domain = "test.com"
sXml = "<?xml version=" "1.0" "encoding=" "gb2312" "?>" &_
"<Package>" &_
"<Domain>" & Domain & "</Domain>" &_
"</Package>"
Set OD = Server.CreateObject ("Microsoft.XMLHTTP")
Od.open "Post", " http://Server/Domain_Check.jsp", False
Od.send (SXML)

If od.status = MB Then
result = Od.responsetext
Set o = Server.CreateObject ("Microsoft.XMLDOM")
O.loadxml (Result)

Domain = CInt (O.selectsinglenode ("//result"). Text)
Response.Write Domain
Set o = Nothing
Set OD = Nothing
End If

2. Server-side parsing packets

<%@ page import= "java.util.*"%>
<%@ page import= "java.text.*"%>
<%@ page import= "java.io.*"%>
<%@ page import= "org.w3c.dom.*"%>
<%@ page import= "javax.xml.parsers.*"%>
<%@ page contenttype= "text/html; CHARSET=GBK "%>
<%
Get Packets
Request.setcharacterencoding ("UTF-8");
BufferedReader in = Request.getreader ();
String Line;
String xmlrequest = "";
String domain_name = "";

while (line = In.readline ())!= null)
{
Constructing packets
XMLRequest = xmlrequest + line + "\ n";
}
Documentbuilderfactory factory = Documentbuilderfactory.newinstance ();
Documentbuilder db = Factory.newdocumentbuilder ();
Bytearrayinputstream stream = new Bytearrayinputstream (xmlrequest.getbytes ("UTF-8"));
Document doc = Db.parse (stream);
Element root = Doc.getdocumentelement ();

NodeList domain = root.getelementsbytagname ("domain");
if (domain.getlength () = = 1) {
Element e = (element) domain.item (0);
domain_name = (String) e.getfirstchild (). Getnodevalue ();
}
Return data
Out.println ("<?xml version=\" 1.0\ "encoding=\" gb2312\ ">\n");
Out.println ("<package>\n");
Out.println ("\t<result>" + domain_name + "</result>\n");
Out.println ("</Package>");
%>

3. Get return results

test.com



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.