"Springmvc+mybatis project" Jie Xin Trade-35. Business Export Report WebService2

Source: Internet
Author: User
Tags soap return tag sendmsg

The last time we created the webservice build of the export report, we just got the XML object of the SOAP structure that WebService gave us, but we didn't parse it. Let's complete the parsing of the soap XML and place the corresponding data in the table via JavaScript.

Let's start with an example of the XML request and the resulting XML reply we SAOP.
Request:
<soapenv:envelope xmlns:soapenv= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0= "http// impl.service.jk.hpu.cn/"xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:xsi=" http://www.w3.org/2001/ Xmlschema-instance "><soapenv:Body><q0:get>  <arg0>39cd8f20-50f8-4bc1-96d5-de6de3d7c8b4 </arg0> </q0:get></soapenv:Body></soapenv:Envelope>

Reply:
<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" ><SOAP:BODY><NS2: GetResponse xmlns:ns2= "http://impl.service.jk.hpu.cn/" ><return>  <consignee> Nanjing </consignee >   <contractids>392bf3b2-cb0e-4e7a-ba02-c91ce83e9fe1,55743f24-f092-47ac-b149-358785437238</ contractids>   <customercontract>3 2</customercontract>   <destinationPort> Shenzhen Port </ destinationport>   <id>39cd8f20-50f8-4bc1-96d5-de6de3d7c8b4</id>   <inputDate> 2015-10-09t00:00:00+08:00</inputdate>   <lcno>T/T</lcno>   <marks>11</marks>   <priceCondition>2</priceCondition>   <remark>22</remark>   <shipmentport > Lianyungang </shipmentPort>   <transportMode>1</transportMode> </return>  </ns2: getresponse>  </soap:Body>  </soap:Envelope>

We analyze the responses to facilitate our interpretation:
<soap:Envelope> is a header file that does not need parsing. We can find that the information we need is placed in the <return> tag pair, and we want to find the information we need from the sub-elements of <return>.

Specific code (on the previous basis):
<%@ page language= "java" pageencoding= "UTF-8"%><%@ include file= ". /.. /base.jsp "%><%@ include file=". /.. /baselist.jsp "%><%@ taglib uri=" http://java.sun.com/jsp/jstl/fmt "prefix=" FMT "%>
The effect after running:


Because we are the export shipping tracking, so we want to add a "status" of the display bar (add to the note below):
<tr>    <td class= "columntitle_mustbe" > Status:</td>    <td class= "tablecontent" id= "state" > </td>   </tr>

There is no state in the back of this time because we have not set a default value, we fill it in the database with a "0" (0-Draft, 1-escalated, 2-decoration, 3-commissioned, 4-Invoice, 5-finance):


This time add the following code to the JS method:
Get the status Var state=ret.getelementsbytagname ("state"); var textnode=state[0].firstchild;var s= ""; if (textnode.nodevalue = = ' 1 ') {    s= "escalated, pending";} else if (textnode.nodevalue== ' 2 ') {    <span style= "White-space:pre" ></span>s= "boxed, to be commissioned";} else if (textnode.nodevalue== ' 3 ') {    s= "delegated, pending Invoice notification";} else if (textnode.nodevalue== ' 4 ') {    s= "invoice, Process completed successfully";} else if (textnode.nodevalue== ' 5 ') {    s= "financial processing";} else if (textnode.nodevalue== ' 0 ') {    s= "Draft processing status";}    document.getElementById ("state"). Innerhtml= "<font color= ' Red ' ><b>" +s+ "</b></font>";

When we click "View" again, we can get the current "status" of the Export report:


We can notice that our ID is written dead, the following we let users enter the query of the number of the report, we go to query:

We modify the HTML, add the shipping number input box:
<TR><TD class= "COLUMNTITLE_MUSTBE" > Shipping code: </TD><TD class= "tablecontent" ><input type= " Text "name=" id "id=" id "/></td></tr>

Then JS Modify:
Send SOAP request function sendmsg () {        var Id=document.getelementbyid ("id"). value;//user input    var url= "http:// Localhost/jx-maven-webapp/cxf/exportserviceimpl ";//webservice request path        var reuqestbody=" <soapenv:envelope Xmlns:soapenv=\ "Http://schemas.xmlsoap.org/soap/envelope/\" "    +" xmlns:q0=\ "http://impl.service.jk.hpu.cn/\" Xmlns:xsd=\ "Http://www.w3.org/2001/xmlschema\" "    +" xmlns:xsi=\ "http://www.w3.org/2001/xmlschema-instance\" > "+" <soapenv:Body><q0:get> <arg0> "+id+" </arg0> </q0:get></soapenv:Body> </soapenv:Envelope> ";        Xmlhttprequest.open ("POST", url,true);//Open link    xmlhttprequest.setrequestheader ("Content-type", "text/xml; Charset=utf-8 ");//Set Request header        Xmlhttprequest.send (reuqestbody);//Send SOAP request        xmlhttprequest.onreadystatechange= _back;//setting the callback function on the onReadyStateChange event}

The part we modify is to get the ID value entered in the input box and then stitch it into the SOAP XML request.

We test, enter the previous ID number, we get the corresponding export information:


But when we enter a non-existent ID number, it is not possible to query the information, we have to check whether our data has been found.

According to the SOAP rule (we can test an empty ID with our test kit last time), if the ID is not present in the sent request, there is no <return> tag in the XML data we return. So we're going to check the return tag, which does not exist and gives the user hints:
callback function _back () {if (xmlhttprequest.readystate==4) {//Commit after completion if (xmlhttprequest.status==200) {var rerxml=x    Mlhttprequest.responsexml; var ret=rerxml.getelementsbytagname ("return") [0];//Gets the return node if (ret!=null) {//Get the shipping number var customcontract=    Ret.getelementsbytagname ("Customercontract");    var textnode=customcontract[0].firstchild;        document.getElementById ("Customcontract"). Innerhtml=textnode.nodevalue;    Obtain a single date var inputdate=ret.getelementsbytagname ("Inputdate");    Textnode=inputdate[0].firstchild;        document.getElementById ("Inputdate"). Innerhtml=textnode.nodevalue;    Obtain the L/C number var lcno=ret.getelementsbytagname ("Lcno");    Textnode=lcno[0].firstchild;        document.getElementById ("Lcno"). Innerhtml=textnode.nodevalue;    Obtain consignee and address Var consignee=ret.getelementsbytagname ("consignee");    var textnode=consignee[0].firstchild;        document.getElementById ("consignee"). Innerhtml=textnode.nodevalue; Get Shipping port var shipmentport=ret.getelementsbytAgName ("Shipmentport");    var textnode=shipmentport[0].firstchild;        document.getElementById ("Shipmentport"). Innerhtml=textnode.nodevalue;    Obtain the port of destination var destinationport=ret.getelementsbytagname ("Destinationport");    var textnode=destinationport[0].firstchild;        document.getElementById ("Destinationport"). Innerhtml=textnode.nodevalue;    Get price conditions var pricecondition=ret.getelementsbytagname ("Pricecondition");    var textnode=pricecondition[0].firstchild;        document.getElementById ("Pricecondition"). Innerhtml=textnode.nodevalue;    Get the mode of transport Var transportmode=ret.getelementsbytagname ("Transportmode");    var textnode=transportmode[0].firstchild;        document.getElementById ("Transportmode"). Innerhtml=textnode.nodevalue;    Obtain the mark-head var marks=ret.getelementsbytagname ("Marks");    var textnode=marks[0].firstchild;        document.getElementById ("Marks"). Innerhtml=textnode.nodevalue;    Get notes Var remark=ret.getelementsbytagname ("remark"); var Textnode=remark[0].firstchild;        document.getElementById ("Remark"). Innerhtml=textnode.nodevalue;    Gets the status Var state=ret.getelementsbytagname ("state");    var textnode=state[0].firstchild;    var s= "";    if (textnode.nodevalue== ' 1 ') {s= "escalated, to be boxed";    }else if (textnode.nodevalue== ' 2 ') {s= "boxed, to be commissioned";    }else if (textnode.nodevalue== ' 3 ') {s= "entrusted, pending invoice notification";    }else if (textnode.nodevalue== ' 4 ') {s= "Invoice, Process completed successfully";    }else if (textnode.nodevalue== ' 5 ') {s= "financial processing";    }else if (textnode.nodevalue== ' 0 ') {s= "Draft processing status"; } document.getElementById ("state"). Innerhtml= "<font color= ' Red ' ><b>" +s+ "</b></font>";} Else{alert ("No query to Data!"); /Clear All data document.getElementById ("Customcontract"). Innerhtml= "";d Ocument.getelementbyid ("Inputdate"). innerHTML= " ";d Ocument.getelementbyid (" Lcno "). Innerhtml=" ";d Ocument.getelementbyid (" consignee "). innerhtml=" "; document.getElementById ("Shipmentport"). Innerhtml= "";d Ocument.getelementbyid ("Destinationport"). innerHTML= ""; document.getElementById ("pRicecondition "). Innerhtml=" ";d Ocument.getelementbyid (" Transportmode "). Innerhtml=" ";d Ocument.getelementbyid (" Marks "). Innerhtml=" ";d Ocument.getelementbyid (" remark "). Innerhtml=" ";d Ocument.getelementbyid (" state "). InnerHTML    ="";} }else{alert ("Access failed!    "); }    }    }

Then test:


Friendly hints are also done!
The last question, we certainly finally can not let the user to enter our ID (UUID of our own can not remember, how can let the user to remember, and there will be a security risk), we could then go to add a dedicated to service WebService get method, We specialize in setting up a mapper to serve it. We can use other fields (the shipping number or the letter of credit number) to inquire.

At this point, our WebService business has been written and completed!

Reprint Please specify source: http://blog.csdn.net/acmman/article/details/49123305

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Springmvc+mybatis project" Jie Xin Trade-35. Business Export Report WebService2

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.