Use xmlhttp in Jsp for data interaction ~

Source: Internet
Author: User
1. The client submits the 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 = 200 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. Parsing data packets on the server side
<% @ 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" %>
<%
// Obtain the data packet
Request. setCharacterEncoding ("UTF-8 ");
BufferedReader in = request. getReader ();
String line;
String xmlRequest = "";
String domain_name = "";
While (line = in. readLine ())! = Null)
{
// Construct a data packet
XmlRequest = xmlRequest + line + "";
}
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 ){
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.