send parameter to servlet and retrieve xml data but I couldn't create xml object
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Lee_Dan
Posted On:   Monday, December 25, 2006 01:24 AM

acctually I imitated Philip McCarthy's cart example. but I couldn't get same result. 1. send parameter to servlet var queryString = "SelectWarehouse=" + param; var handlerFunction = getReadyStateHandler(xmlhttp4 , updateStockQty ); var youRL = "/StockQtyArryServlet"; xmlhttp4.open("POST", youRL, true); xmlhttp4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp4.onreadystatechange = handlerFunction; xmlhttp4.send(queryString); 2. here's servlet code pstmt = con.prepareStatement(query); pstmt.setString(1, StorageCd); rs = pstmt.exe   More>>

acctually I imitated Philip McCarthy's cart example. but I couldn't get same result.



1. send parameter to servlet


var queryString = "SelectWarehouse=" + param;


var handlerFunction = getReadyStateHandler(xmlhttp4 , updateStockQty );

var youRL = "/StockQtyArryServlet";

xmlhttp4.open("POST", youRL, true);

xmlhttp4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

xmlhttp4.onreadystatechange = handlerFunction;

xmlhttp4.send(queryString);



2. here's servlet code



pstmt = con.prepareStatement(query);

pstmt.setString(1, StorageCd);

rs = pstmt.executeQuery();

response.setContentType("application/xml");

response.setHeader("Cache-Control", "no-cache");


out.println (" <?xml version="1.0"?>");


while (rs.next()) {

out.println (" ");

out.println (" ");

out.println (" ");

out.println (rs.getString("GOODS_NM"));

out.println (" ");

out.println (" ");

out.println (rs.getString("STORE_QTY"));

out.println (" ");

out.println (" ");

out.println ("
");



3. then retrieve this xml object here



function getReadyStateHandler( xmlhttp4, responseXmlHandler) {


return function () {


if (xmlhttp4.readyState == 4) {

if (xmlhttp4.status == 200) {
responseXmlHandler(xmlhttp4.responseXML);



} else if (xmlhttp4.status == 404) {

//error
alert("Request URL does not exist");


} else {

//error
alert("Error: status code is " + xmlhttp4.status);


}

}

}

}



4. finally I want to test this xml object whether to correct like this



function updateStockQty (responsedXML){
items =
responsedXML.getElementsByTagName("item");

alert(items.length);

}



Q1. but javascript returns 0, I am not sure that xml file was created properly. how can I prove it?



Q2. I tried to use various DOM command but it didn't work.



thanks in advance and Merry X-mas

   <<Less

Re: send parameter to servlet and retrieve xml data but I couldn't create xml object

Posted By:   Muthamil_selvi  
Posted On:   Friday, December 29, 2006 05:01 AM

Try to access your servlet ie StockQtyArryServlet directly .
ie http://yourhost/StockQtyArryServlet


Check whether it displays the xml file in correct format and with out any error like "not well formed xml file " .


If it does not display correctly ,then you have modify ur servlet code .

/Prabakar.

Re: send parameter to servlet and retrieve xml data but I couldn't create xml object

Posted By:   Lee_Dan  
Posted On:   Monday, December 25, 2006 02:33 AM

ask and anwer by myself, lol

the answer is my xml is invalid. that's all

thanks
About | Sitemap | Contact