//test.jsp
<%@page import="javaBean.simpleBean"%>
<%
out.clear(); //避免出现多余html代码
request.setCharacterEncoding("UTF-8"); //避免中文乱码
response.setCharacterEncoding("UTF-8");
simpleBean a=new simpleBean();
out.println(a.returnName("1234"));
%>
~~~~~~~~~~~~~~~~~~~~~~
//simpleBean.java
package javaBean;
public class simpleBean {
public String returnName(String name)
{
if(name.equals(""))
{
return "&data=hello guest";
}else{
return "&data=hello"+name;
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
//as3 code LoginPage.as关联到fla中,定义了一个btn和txt
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.system.System;
/**
* ...
* @author amyblog.ml
*/
public class LoginPage extends Sprite
{
public function LoginPage()
{
super();
main();
}
private function main():void
{
System.useCodePage=true;
btn.addEventListener(MouseEvent.CLICK,loadMss);
}
private function loadMss(e:MouseEvent):void
{
var postLoader:URLLoader=new URLLoader();
var request:URLRequest=new URLRequest();
var vars:URLVariables=new URLVariables();
vars.s1="flash";
vars.s2="flex";
request.url="http://https://https://amyflash.com:8080/myproject/test.jsp";
request.method=URLRequestMethod.POST;
request.data=vars;//这里的data可以是一个Object,或者Array
postLoader.load(request);
postLoader.addEventListener(Event.COMPLETE,completeFun);
}
private function completeFun(e:Event):void
{
txt.text = "test:" + (e.currentTarget as URLLoader).data;
trace(e.target.data);
//trace((e.currentTarget as URLLoader).data);
}
}
}