加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 与 java交互的方法

发布时间:2020-12-15 04:04:29 所属栏目:百科 来源:网络整理
导读:距离flex4刚刚出来也有一段时间了,相信对于大多数的flex 爱好者来说,能够尝试完成 flex 与 java 交互 已经很不错了。但是,本人作为一个资深的使用flex 开发的爱好者,前些日子已经尝试 分别用代码实现了三种 flex4 与 Java 的顺利通信。现在,我就来和大

 
距离flex4刚刚出来也有一段时间了,相信对于大多数的flex爱好者来说,能够尝试完成flexjava交互已经很不错了。但是,本人作为一个资深的使用flex开发的爱好者,前些日子已经尝试分别用代码实现了三种flex4Java的顺利通信。现在,我就来和大家一起来分享一下我的心得。



我所使用的三种flex4Java顺利通信的方式是:


1 flex与普通java类通信RemoteObject;?


2 flex与服务器交互HTTPService


3 flexwebservice交互WebService



当大家尝试使用flex与普通java类通信时,我推荐大家用RemoteObject,具体的代码段如下:? ?? ???

package com.flex.demo;

/**

*?功能描述:该类用来实现flex与普通java类中的方法通信

* @author Administrator

*

*/

//以上是打头的功能描述,可以不写。



<!--flex?与普通java类通信-->

? ?? ???<s:RemoteObject id=“serv“ destination=“myservice“ fault=“serv_faultHandler(event)“ result=“serv_resultHandler(event)“>

? ?? ?? ?? ? <properties>

? ?? ?? ?? ?<source>com.flex.demo.SimpleService</source>

? ?? ???</properties>

? ?? ???</s:RemoteObject>

? ??





?flex?与服务器交互HTTPService? ? servlet代码? ? ? ? ?



/**

*?功能描述:servlet用来与flex进行交互

* @author Administrator

*

*/

@SuppressWarnings(“serial“)

public class SimpleServiceServlet extends HttpServlet {

? ?

? ? @Override

? ? protected void service(HttpServletRequest request,HttpServletResponse response)

? ?? ?? ?? ?throws ServletException,IOException {

? ?? ???request.setCharacterEncoding(“utf-8“);

? ?? ???response.setCharacterEncoding(“utf-8“);

? ?? ???response.getWriter().write(“我是服务器“);

? ? }

}



接下去我来介绍一下第二种方法:flex与服务器交互HTTPService,代码段如下,希望大家能够看懂,并且从中获得经验:


<!-- flex?与服务器交互-->

? ?? ???<s:HTTPService id=“service“ fault=“service_faultHandler(event)“ result=“service_resultHandler(event)“ url=“http://localhost:8080/flexdemo/simpleServiceServlet“>

? ?? ?? ?? ?

? ?? ???</s:HTTPService>

? ?? ???flexwebservice交互WebService

<!--flexwebservice交互这里调用一个天气预报的webservice-->

? ?? ???<s:WebService id=“ws“

? ?? ?? ?? ?? ?? ?? ? wsdl=“http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl“

? ?? ?? ?? ?? ?? ?? ? fault=“ws_faultHandler(event)“

? ?? ?? ?? ?? ?? ?? ? result=“ws_resultHandler(event)“

? ?? ?? ?? ?? ?? ?? ? showBusyCursor=“true“>

? ?? ?? ?? ?<!--?第二种调用webservice的方法<s

peration>-->

? ?? ?? ?? ?另外,我想说一下的是,对于弹出框的代码段虽然是很简单的,但是也最好不要漏掉:

??protected function service_faultHandler(event:FaultEvent):void

? ?? ?? ?? ?{

? ?? ?? ?? ?? ? Alert.show(“调用失败了:“+event.fault.message as String,“提示“);

? ?? ?? ?? ?}

//表示调用成功的。

protected function service_resultHandler(event:ResultEvent):void

? ?? ?? ?? ?{

? ?? ?? ?? ?? ? Alert.show(“调用成功了:“+event.result as String,“提示“);

? ?? ?? ?? ?}

//表示调用失败的。

三种flexjava交互的方式就是完整的配置,大家只要注意加上下面这样的代码段:

<![CDATA[

? ?? ?? ?? ?import mx.controls.Alert;

? ?? ?? ?? ?import mx.rpc.events.FaultEvent;

? ?? ?? ?? ?import mx.rpc.events.ResultEvent;

>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读