程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> Jsp中使用xmlhttp進行數據交互~

Jsp中使用xmlhttp進行數據交互~

編輯:關於JSP

1.客戶端提交請求
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.服務器端解析數據包
<%@ 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" %>
<%
//獲得數據包
request.setCharacterEncoding("UTF-8");
BufferedReader in = request.getReader();
String line;
String xmlRequest = "";
String domain_name = "";
while ((line = in.readLine()) != null)
{
//構造數據包
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) {

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved