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. PHP读取Mongodb数据报错,Cannot natively represent the long 8331412483000 on this platform

    在使用PHP进行读取Mongo数据时,如果读取的int数据过大时,会自动转变为int64位. 并会报以下错误: Cannot natively represent the long 833141248 ...

  2. OpenJDK和OracleJDK的JVM性能有多大差距

    首先要先明确OpenJDK和Sun/OracleJDK之间,以及OpenJDK 6.OpenJDK 7.OpenJDK 7u和OpenJDK 8等项目之间是什么关系,这有助于确定接下来编译要使用的JD ...

  3. Python代码编辑器

    PyCharm Community 说到PyCharm Community,我们就会想到它是一款免费的开源Python代码编辑器,不过这也是事实啦.PyCharm Community为我们提供了轻量级 ...

  4. Android模拟器使用教程

    Using the Emulator In this document Overview Android Virtual Devices and the Emulator Starting and S ...

  5. REST简析

    内容译自英文原文:A Brief Introduction to REST 不知你是否意识到,围绕着什么才是实现异构的应用到应用通信的“正确”方式,一场争论正进行的如火如荼:虽然当前主流的方式明显地集 ...

  6. Hibernate 的<generator class="native"></generator>的不同属性含义

    1) assigned主键由外部程序负责生成,无需Hibernate参与. 2) hilo通过hi/lo 算法实现的主键生成机制,需要额外的数据库表保存主键生成历史状态. 3) seqhilo与hil ...

  7. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)

    题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ...

  8. typedef struct trx_struct trx_t;

    /* The transaction handle; every session has a trx object which is freed only when the session is fr ...

  9. LA 2678 Subsequence

    有一个正整数序列,求最短的子序列使得其和大于等于S,并输出最短的长度. 用数组b[i]存放序列的前i项和,所以b[i]是递增的. 遍历终点j,然后在区间[0, j)里二分查找满足b[j]-b[i]≥S ...

  10. Core Text

    Core Text 本文所涉及的代码你可以在这里下载到 https://github.com/kejinlu/CTTest,包含两个项目,一个Mac的NSTextView的测试项目,一个iOS的Cor ...