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组件调用的更多相关文章

  1. vue全局引入公共scss样式,子组件调用

    前提 已引用并使用scss npm install sass-loader --save-dev npm install node-sass --sava-dev 配置 在vue.config.js中 ...

  2. 此操作失败的原因是对 IID 为“{000208DA-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface

    有些电脑报错,有些电脑正常. 环境:VS2010 WinForm程序, Office2007 C#操作Excel时报错.错误: 无法将类型为“System.__ComObject”的 COM 对象强制 ...

  3. 无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”。此操作失败的原因是对 IID 为“{000208D5 -0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 加载类型库/DLL 时出错。 (异常来 自 HRESULT:

    无法将类型为“Excel.ApplicationClass”的 COM 对象强制转换为接口类 型“Excel._Application”.此操作失败的原因是对 IID 为“{000208D5 -000 ...

  4. flex的Accordion组件头部文本居中显示

    flex的Accordion组件头部文本默认是居左的,可以通过设置headerStyleName属性使之居中,另外还可以设置字体的样式等 <?xml version="1.0" ...

  5. 最原始的COM组件调用过程(不使用注册表信息)

    最原始的COM组件调用过程(不使用注册表信息) 最近因为项目的关系开始研究COM组件了,以前都认为COM过时了,所以也没怎么接触. 现在好好补补课了. 一般调用COM都是通过注册表找到它的位置, 然后 ...

  6. 为operamasks增加HTML扩展方式的组件调用

    #为operamasks增加HTML扩展方式的组件调用 ##背景 之前的[博文](http://www.cnblogs.com/p2227/p/3540858.html)中有提及到,发现easyui中 ...

  7. flex与js相互调用

    1.flex调用js方法 调用方法例如:ExternalInterface.call("UploadComplete",oldName,uidName,_dir+"/&q ...

  8. K2 BPM项目 基于COM组件调用SAP RFC 问题

    K2 BPM项目 基于COM组件调用SAP RFC 问题 问题前景: 环境:Win 2008 R2 64bit 最近项目中有支流程需求中需要在会计入账环节回写SAP的会计凭证. SAP组给我们提供.N ...

  9. Flex父子窗口相互调用

    Flex父子窗口相互调用 1.设计思路 (1)子窗口调用父窗口的方法 (2)子窗口做了修改后,返回父窗口,父窗口调用子窗口函数 2.设计源码 (1)父窗口 ParentWindow.mxml: < ...

随机推荐

  1. (5)XML转化成TXT

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  2. [CFGym101061G] Repeat it(逆元)

    题目链接:http://codeforces.com/gym/101061/problem/G 题意:给一个数字n,让你重复m次,求最后这个数对1e9+7取模的结果. 思路:设数字n长度为k,重复m次 ...

  3. 《OD大数据实战》Hive入门实例

    官方参考文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual 一.命令行和客户端 1. 命令窗口 1)进入命令窗口 hi ...

  4. CFileDialog使用总结

    http://blog.csdn.net/tianhai110/article/details/2055149 CFileDialog经常用,但经常忘,现归纳整理下,方便今后查询. 例子: CFile ...

  5. 函数fsp_fill_free_list

    /**********************************************************************//** Puts new extents to the ...

  6. 51nod1158 全是1的最大子矩阵

    跟最大子矩阵差不多O(n3)扫一下.有更优写法?挖坑! #include<cstdio> #include<cstring> #include<cctype> #i ...

  7. 4630 no pain no game 树状数组

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4630 题意:给你N个数,然后给你M个询问,每个询问包含一个l 一个r,问你lr 这个区间中任意两个数最 ...

  8. Java之网络编程笔记

    网络通讯要素: 1.IP地址 IP地址:用于标记一台计算机的身份证. IP地址由网络地址(确定网络)和主机地址(网络中的主机)组成. IP地址分为A类地址.B类地址.C类地址(常用).D类地址.E类地 ...

  9. LeetCode Reverse Linked List II 反置链表2

    题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...

  10. phonegap 退出确认

    实现 再按一次退出  ,这里只针对 主active继承 DroidGap 或者CordovaActive 以下有2种 方案1: 重写CordovaWebView类 新建类NobackWebView p ...