三種flex4與Java順利通信的方式是:
flex與普通java類通信RemoteObject;
flex與服務(wù)器交互HTTPService;
flex與webservice交互WebService。
當(dāng)大家嘗試使用flex與普通java類通信時(shí),一般用RemoteObject,具體的代碼段如下:
package com.flex.demo;
/**
*第一種 功能描述:該類用來實(shí)現(xiàn)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>
[js] view plaincopy
<!--flex 與服務(wù)器交互HTTPService-->
<!--servlet代碼-->
/**
* 第二種 功能描述:該servlet用來與flex進(jìn)行交互
* @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(“我是服務(wù)器“);
}
}
$news_page$
flex與服務(wù)器交互HTTPService,flex端代碼
<!-- flex 與服務(wù)器交互-->
<s:HTTPService id=“service“ fault=“service_faultHandler(event)“ result=“service_resultHandler(event)“ url=“http://localhost:8080/flexdemo/simpleServiceServlet“>
</s:HTTPService>
<!--第三種 flex與webservice交互WebService-->
<!--flex與webservice交互這里調(diào)用一個(gè)天氣預(yù)報(bào)的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“>
<!-- 調(diào)用webservice的方法<speration>-->
另外,我想說一下的是,對(duì)于彈出框的代碼段雖然是很簡(jiǎn)單的,但是也最好不要漏掉:
protected function service_faultHandler(event:FaultEvent):void{
Alert.show(“調(diào)用失敗了:“+event.fault.message as String,“提示“);
}
protected function service_resultHandler(event:ResultEvent):void{
Alert.show(“調(diào)用成功了:“+event.result as String,“提示“);
}
<span style="font-family:Arial; background-color:#ffffff"></span>
更多信息請(qǐng)查看IT技術(shù)專欄