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();
}
相关文档:
Step 1:Form1 上添加一个ToolStripContainer控件
Step2:实现代码
private void Form2_Load(object sender, EventArgs e)
{
CMenuEx menu = new CMenuEx();
string sPath = "D:\\Menu.xml";//xml的内容
if (menu.FileExit())
&nb ......
xml:
<?xml version="1.0" encoding="utf-8" ?>
<library>
<name>首都图书馆</name>
<address>朝阳区华威桥南</address>
<books>
<book>
<id>0000</id>
</book>
< ......
首先要求大家到数据库建立一个数据库,在我这例子中数据库名为userDb,建立一个表userInfo,里面设置两个字段一个为id,一个为name。
创建以下java代码在src目录下
User.java
package org.rjb.java;
public class User {
private String name;
public String getName() {
return name;
}
public voi ......
<Records>
<Record>
<id>1 </id>
<name>李四 </name>
</Record>
<Record>
<id>2 </id>
<name>张三 </name>
</Record>
<Record>
<id>3 </id>
<name>王五 </name>
</Record& ......
/*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 ......