PDA

View Full Version : how to use xml.sendandload with Java Servlet


jyu
04-10-2003, 04:01 AM
Hello, guys, any one knows how to use XML.sendandload with a Java servlet.
Say, I have following code in my flash movie:


"sendXml = new XML("<p>Dog</P>");//create the send xml object
eventXml=new XML();
eventXml.ignoreWhite = true;//take care of white space, which may interfere with
//your reading of the xml otherwise
eventXml.onLoad = function(cool)//here,no matter what variable name you will use
//the variable is always set to a boolean value
{
if(cool){
//this toString() gives you the contents of the xml file in string format
//trace(this.toString());
eventItem = this.firstChild.childNodes;//our xml file is pretty simple
//with only one child,but this child has three children
//processing xml
//......blah blah blah

}//end of if(cool)
}//end of onload function

//the call to load method is always put at this postion, after we define
//the onload method


sendXml.sendAndLoad("http://degas.ecom.arizona.edu:5081/JiaoYu/servlet/Hello6",eventXml);//name of our xml file, in the same folder as this fla "

If I want to parse the xml part sent to the servlet, i.e. "<p>dog</p>", how can I do it in the servlet?
Thanks so much.

jyu
05-17-2003, 08:08 AM
Finally, I got the answer to my own quesiton.

The key is at the Java servlet, and it is so simple after you know it.

Just do this in the Servlet:
"
import java.io.*;

BufferedReader br=req.getReader();
String reqBody=br.readLine();

"
Then parse the xml from string using any java xml parser.

A free one is available at www.jdom.orgHello, the problem is fixed finally

jyu
06-12-2003, 06:34 AM
Another thing you may want to pay attention to is to use doPost method in the servlet instead of the doGet, this is almost always true with servlet working with FLash