Flex 与 servlet 通信 【xml】
String userId = request.getParameter("userId");
System.out.println(userId);
response.setCharacterEncoding("UTF-8");
//response.getWriter().println("hello world -- 我爱你。。。");
String xml = "<user>" +
"<username>涛哥</username>" +
"</user>";
response.getWriter().println(xml);
import flash.trace.Trace;
private var loader:URLLoader = new URLLoader();
private function asCallHandler():void{
// URL
var url:String = "http://localhost/app01/getUser";
// 参数
var args:URLVariables = new URLVariables();
args.userId = 1;
// Request请求
var request:URLRequest = new URLRequest(url);
request.data = args;// 绑定参数
//请求加载器
loader.addEventListener(Event.COMPLETE,handleServerResponse);
loader.load(request);//发送请求
}
private function handleServerResponse(e:Event):void{
trace("User data is loaded");
//将返回的数据解析成xml
var resultXML : XML = new XML(loader.data);
var uname : String = resultXML.username[0];
debugText.text = uname;
}
protected function button1_clickHandler(event:MouseEvent):void
{
// 发送请求
asCallHandler();
}
相关文档:
xml:
<?xml version="1.0" encoding="utf-8" ?>
<library>
<name>首都图书馆</name>
<address>朝阳区华威桥南</address>
<books>
<book>
<id>0000</id>
</book>
< ......
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
<mx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import mx.core.DragSource;
import mx.events.DragEvent;
import mx.managers.DragManager;
private var xoffset:Number;
private var yoffset:Number;
priv ......
/*Copyright (c) 2006 Adobe Systems Incorporated
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, m ......
文章来源:IT工程技术网 http://www.systhinker.com/html/43/n-11643.html
用的是一种很笨的方法,但可以帮助初学者了解访问XML节点的过程。
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
......