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. Java 字符串拼接方式

    import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.StringUtils; impor ...

  2. django中的filter详解

    filter (数据过滤) 我们很少会一次性从数据库中取出所有的数据:通常都只针对一部分数据进行操作. 在Django API中,我们可以使用`` filter()`` 方法对数据进行过滤: > ...

  3. 《c程序设计语言》读书笔记--大于8 的字符串输出

    #include <stdio.h> #define MAXLINE 100 #define MAX 8 int getline(char line[],int maxline); voi ...

  4. 使用 httpkit 来替代 jetty

    Compojure 是一个基于 ring 的上层web开发框架.在 lein new compojure my-app 生成的项目中,默认是启用 jetty 服务器的,最近用到了 http-kit 中 ...

  5. MySQL之Join

    参见MySQL(以5.1为例)中官方手册:MySQL官方手册-JOIN 假设有以下几个表 t1 id book 1 java 2 c++ 3 php t2 id author 2 zhang 3 wa ...

  6. HeadFirst 13 (包装器, 过滤器) not Finish

    过滤器准许你拦截请求 容器管理过滤器的生命周期 都在DD中声明

  7. 投影纹理映射(Projective Texture Mapping)

    摘抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人”  投影纹理映射( Projective ...

  8. POJ 3254 (状压DP) Corn Fields

    基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...

  9. 51nod1406 与查询

    这题卡I/O...dp一下... #include<cstdio> #include<cstring> #include<cctype> #include<a ...

  10. MapView的用法

    一.MapView 1.显示用户的位置点(用蓝色圆点标记) mapView.showsUserLocation = YES; 2.代理方法 1> 当定位到用户的位置就会调用 - (void)ma ...