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();
}
相关文档:
using System.Xml;
//初始化一个xml实例
XmlDocument xml=new XmlDocument();
//导入指定xml文件
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//指定一个节点
XmlNode root=xml.SelectSingleNode("/root");
//获取节点下所有直接子节点
XmlNodeList childlist=root ......
<?xml version="1.0"?>
<BANK_CREATE01>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT=" ......
1。写一个xml文件
<?xml version="1.0" encoding="utf-8" ?>
- <root>
- <user id="101">
<name>abc</name>
<password>abc</password>
</user>
- <user id="102">
<name>ccc</name>
<password>ccc< ......
flex 页面跳转
方法一:使用navigateToURL
var url:String = "http://localhost/flex/test.jsp";
var request:URLRequest = new URLRequest(url);
navigateToURL(request,"_self");
方法二:引用flash中的 import flash.external.ExternalInterface 这个接口
他能提供像js中window.location.href方法一样方便
Extern ......