Flex之HTTPService组件调用
1、采用<s:HTTPService>标签来实现:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" >
<s:Label x="61" y="138" text="HttpService:"/>
<s:TextInput x="152" y="128" id="http_txt"/>
<s:Button x="289" y="129" id="btn_login" label="发送" click="button2_clickHandler(event)"/>
<s:Label x="383" y="138" id="http_result"/>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
//HttpService的形式访问Java服务器
protected function button2_clickHandler(event:MouseEvent):void
{
btn_login.addEventListener(MouseEvent.CLICK,login);
//加载HTTPService的返回监听
httpSer.addEventListener(ResultEvent.RESULT,httpSerResultHandler);
httpSer.addEventListener(FaultEvent.FAULT,httpSerFaultHandler);
}
private function login(event:MouseEvent):void{
httpSer.send();//发送请求
}
//返回成功事件
private function httpSerResultHandler(event:ResultEvent):void{
Alert.show(event.result.toString(),"登录提示");
}
//返回失败事件
private function httpSerFaultHandler(event:FaultEvent):void{
Alert.show(event.fault.message as String,"登录提示");
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="httpSer" url="http://localhost:8080/html/FlexServlet" method="POST">
<s:request>
<!--需要发送到服务器的参数名,及值,接收参数名时必须一致i。其中name表示参数名称。-->
<name>{http_txt.text}</name>
</s:request>
</s:HTTPService>
</fx:Declarations>
</s:Application>
2、采用创建HTTPService对象:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" >
<s:Label x="61" y="138" text="HttpService:"/>
<s:TextInput x="152" y="128" id="http_txt"/>
<s:Button x="289" y="129" id="btn_login" label="发送" click="button2_clickHandler(event)"/>
<s:Label x="383" y="138" id="http_result"/>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.http.HTTPService;
protected function button2_clickHandler(event:MouseEvent):void
{
var http:HTTPService = new HTTPService();
http.url = "http://localhost:8080/html/FlexServlet0?name="+http_txt.text;
http.send();
http.addEventListener(ResultEvent.RESULT,httpSerResultHandler);
http.addEventListener(FaultEvent.FAULT,httpSerFaultHandler);
}
private function login(event:MouseEvent):void{
httpSer.send();//发送请求
}
//返回成功事件
private function httpSerResultHandler(event:ResultEvent):void{
Alert.show(event.result.toString(),"登录提示");
}
//返回失败事件
private function httpSerFaultHandler(event:FaultEvent):void{
Alert.show(event.fault.message as String,"登录提示");
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
</s:Application>
3、在JavaWeb项目中新建Servlet(FlexServlet) :
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();
pw.write("你好["+name+"]这是来自Httpservice的消息...当前Session是:"+request.getSession());
pw.close();
}
Flex之HTTPService组件调用的更多相关文章
- vue全局引入公共scss样式,子组件调用
前提 已引用并使用scss npm install sass-loader --save-dev npm install node-sass --sava-dev 配置 在vue.config.js中 ...
- 此操作失败的原因是对 IID 为“{000208DA-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface
有些电脑报错,有些电脑正常. 环境:VS2010 WinForm程序, Office2007 C#操作Excel时报错.错误: 无法将类型为“System.__ComObject”的 COM 对象强制 ...
- 无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”。此操作失败的原因是对 IID 为“{000208D5 -0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 加载类型库/DLL 时出错。 (异常来 自 HRESULT:
无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”.此操作失败的原因是对 IID 为“{000208D5 -000 ...
- flex的Accordion组件头部文本居中显示
flex的Accordion组件头部文本默认是居左的,可以通过设置headerStyleName属性使之居中,另外还可以设置字体的样式等 <?xml version="1.0" ...
- 最原始的COM组件调用过程(不使用注册表信息)
最原始的COM组件调用过程(不使用注册表信息) 最近因为项目的关系开始研究COM组件了,以前都认为COM过时了,所以也没怎么接触. 现在好好补补课了. 一般调用COM都是通过注册表找到它的位置, 然后 ...
- 为operamasks增加HTML扩展方式的组件调用
#为operamasks增加HTML扩展方式的组件调用 ##背景 之前的[博文](http://www.cnblogs.com/p2227/p/3540858.html)中有提及到,发现easyui中 ...
- flex与js相互调用
1.flex调用js方法 调用方法例如:ExternalInterface.call("UploadComplete",oldName,uidName,_dir+"/&q ...
- K2 BPM项目 基于COM组件调用SAP RFC 问题
K2 BPM项目 基于COM组件调用SAP RFC 问题 问题前景: 环境:Win 2008 R2 64bit 最近项目中有支流程需求中需要在会计入账环节回写SAP的会计凭证. SAP组给我们提供.N ...
- Flex父子窗口相互调用
Flex父子窗口相互调用 1.设计思路 (1)子窗口调用父窗口的方法 (2)子窗口做了修改后,返回父窗口,父窗口调用子窗口函数 2.设计源码 (1)父窗口 ParentWindow.mxml: < ...
随机推荐
- Volley HTTP库系列教程(3)自定义RequestQueue和编写单例RequestQueue示例
Setting Up a RequestQueue Previous Next This lesson teaches you to Set Up a Network and Cache Use a ...
- typedef struct trx_struct trx_t;
/* The transaction handle; every session has a trx object which is freed only when the session is fr ...
- 函数lock_rec_add_to_queue
在原来的type_mode基础上,加上LOCK_REC /*********************************************************************// ...
- git cheatsheet小抄本
https://www.kernel.org/pub/software/scm/git/docs/git.html
- XE4 IOS开发环境配置
l 配置IOS的安装开发环境 使用RAD XE4开发IOS程序,一台MAC是必须的(也可以用虚拟机), MAC上需要安装Xcode, 独立版本的Commnand Line Tools 以及RAD的pa ...
- [ionic开源项目教程] - 第4讲 通Service层获取数据列表
第4讲:通Service层获取数据列表 上一讲中页面的基本架构已完成,这一讲介绍如何通过service层从服务器请求数据,在通过controller层为载体,显示到视图层. 1.在services.j ...
- 漫游Kafka实现篇之分布式
Zookeeper节点标记 当路径中的元素包括在方括号里比如[xyz],则表示xyz表示的值是不固定的,每个可能的值都有一个Zookeeper节点.比如/topics/[topic]表示每个topic ...
- 每个极客都应该知道的Linux技巧
每个极客都应该知道的Linux技巧 2014/03/07 | 分类: IT技术 | 0 条评论 | 标签: LINUX 分享到:18 本文由 伯乐在线 - 欣仔 翻译自 TuxRadar Linux. ...
- 【转载】Windows 7下使用bcdedit删除多余启动项的命令
在Windows 7中是使用bcdedit来代替Windows XP中的boot.ini bcdedit位置:C:\Windows\System32 (直接使用命令bcdedit即可) bcdedi ...
- hibernate不关闭session后果
(转自:百度知道) 看是怎么获得session的. 方法1: 通过配置监听器后,在Dao中用getCurrentSession获取(内部原理....),此时无需管理session的关闭与否: 方法2: ...