flex调用java

flex 调用java配置多个java类:
第一个remoting-config.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service-2"
class="flex.messaging.services.RemotingService">

<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>

<destination id="ImageProcess">
<properties>
<source>cn.ImageProcess</source>
</properties>
</destination>
</service>

第二个remoting-config-2.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">

<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>

<destination id="test">
<properties>
<source>cn.com.test</source>
</properties>
</destination>
</service>

services-config.xml文件中的server部分:
 <services>
<service-include file-path="remoting-config-2.xml" />
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
</services>

felx调用代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.collections.ArrayCollection;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.AbstractOperation ;

public function submit():void{
var remote:RemoteObject = new RemoteObject();
//调用在J2EE端remoting-config.xml中配置的暴露出的类的名称 id
remote.destination = "ImageProcess";
// remote.destination = "test";
//调用J2EE端类中的方法
var o:AbstractOperation = remote.getOperation("setAlphaPath");
o.send("E:\\workspace2\\gisImage\\flex_src\\assets\\hh-1.png","hh-4.png",4);
// remote.setHello();

// var o:AbstractOperation = remote.getOperation("ceshi");
// o.send("E:\\workspace2\\gisImage\\flex_src\\assets\\hh-1.png");

//监听调用成功事件
o.addEventListener(ResultEvent.RESULT,result);
//监听失败事件
o.addEventListener(FaultEvent.FAULT,fault);
}

private function result(evt:ResultEvent):void{
Alert.show(evt.result.toString());
}

private function fault(evt:FaultEvent):void{
Alert.show("调用失败!");
}
]]>
</mx:Script>

<mx:Button click="submit()" label="hello" horizontalCenter="0" verticalCenter="0"/>

</mx:Application>


java代码test类:

package cn.com;

import java.util.*;
public class test {

public String ceshi(String mm)
{
return "lllllllll"+mm;
}

}

java代码,ImageProcess类

package cn;


public class ImageProcess{

public String setAlphaPath(String srcImageFile, String descImageDir,int alpha ) {



return "assetsff/"+descImageDir;
}

}


注意: (1)要让flex掉用的java方法,则java方法必须是公有的。
(2)虽然可以调用多个java类但是最好是在java类中定义公有的方法,传递其它的类的类名,方法名,等灵活调用,以后研究一下。
(3)注意flex工程的配置文件:如编译器:services "E:/workspace2/gisImage/WebRoot/WEB-INF/flex/services-config.xml" -locale en_US -source-path=locale/{locale} -keep-all-type-selectors=true
flex服务器等,下面会有配置的截图。
[img]http://dl.iteye.com/upload/attachment/0068/6451/fff92bd2-35b9-35b5-9ca4-e53486e15686.png[/img]
[img]http://dl.iteye.com/upload/attachment/0068/6453/115e8c53-6021-3d6c-b0bc-b09af61c1b58.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值