我想连接Java和FLEX。我从未使用过Java,而且我的PC上也没有安装Java。因此,从安装Java到从FLEX调用Java方法,再从Java到FLEX接收结果,我需要一些步骤,所以任何人都可以帮助我连接Java和FLEX。
发布于 2012-02-06 20:26:11
请执行以下步骤。这肯定会对你有所帮助。
1在系统中安装JDK
2复制c驱动器中的apache tomcat服务器。
3设置环境变量(1)变量名: JAVA_HOME
Variable Value : C:\Program Files\Java\jdk1.7.0 (2) Variable Name : CATALINE\_HOME Variable Value : C:\apache-tomcat-6.0.35-windows-x86\apache-tomcat-6.0.354更新变量值中的Path环境变量,添加过滤路径(1)C:\apache-tomcat-6.0.35-windows-x86\apache-tomcat-6.0.35\bin (2)C:\Program Files\Java\jdk1.7.0\bin
5在webapps文件夹中创建Blazeds文件夹并解压blazeds.war文件
Two folder there (1)WEB-INF (2)META-INF6在C:\apache-tomcat-6.0.35-windows-x86\apache-tomcat-6.0.35\webapps\FlexJavaIntegration\WEB-INF\classes中创建文件夹名称示例
7在示例文件夹中创建Java文件java文件的内容如下
package example;
import java.util.Date;
public class HelloWorld
{
public HelloWorld()
{
}
public String getHelloWorld(String name,String name1)
{
String result = null;
result = name + " and " + name1;
return result;
}
public String getCurrentDate(String name)
{
String result = null;
result = " Current Date is:" + new Date();
return result;
}
}8在CMD中编译.java文件
javac HelloWorld.java9转到文件夹C:\apache-tomcat-6.0.35-windows-x86\apache-tomcat-6.0.35\webapps\FlexJavaIntegration\WEB-INF\flex,编辑remoting-config.xml文件并添加目标
<destination id="helloworld">
<properties>
<source>example.HelloWorld</source>
</properties>
<adapter ref="java-object" />
</destination>10从CMD启动Tomcat服务器,转到Tomcat服务器文件夹的bin文件夹,在cmd中运行startup.bat文件,然后启动Tomcat服务器在浏览器中检查:"localhost:8080“URl,如果要关闭tomcat服务,请在CMD shutdown.bat中写入以下命令
11创建新的Flex应用程序选择服务器技术- J2EE
12单击“下一步”并设置以下属性
Root Folder : C:\apache-tomcat-6.0.35-windows-x86\apache-tomcat-6.0.35\webapps\blazeds
Root URL : http://localhost:8080/blazeds
Context Root : /blazeds
And Validate Configuration 13远程对象语法如下
<mx:RemoteObject id="ro" destination="helloworld" source="example.HelloWorld" result="resultHandler(event)" fault="faultHandler(event)"/>
---------destination in RemoteObject is id of destination in remoting-config.xml
---------source in RemoteObject is source of destination in remoting-config.xml14现在调用Java方法,如下所示
<mx:Button label="Get Hello World!" click="ro.getHelloWorld(txt1.text,txt2.text)"/>
<mx:Button label="Get Time" click="ro.getResults(txt1.text)" />
Here ro is id of RemoteObject and getHelloWorld & getResults is method from JAVA file.15您可以从java类文件中获得结果。
注意:您需要在PC上安装BLAZEDS和APACHE TOMCAT服务器
发布于 2012-02-06 20:23:00
这在这个java world entry中有很好的描述
您有两个选择来让Flex语言与Java对话:-对象远程处理- SOAP -其他基于HTTP的webservices -...
如果我是你,我会尝试一种轻量级的restful方法,将你的数据从一个地方转移到另一个地方,这样你也可以切换技术。
https://stackoverflow.com/questions/9159973
复制相似问题