java 中Flex开发RemoteOject 配置详解
java后台配置如下
1。在下载BlazeDS类包
2。解压将BlazeDS中flex配置文件拷贝到web-inf目录下
3。在remote-config。xml配置暴露的服务信息。
4。在修改web。xml文件配置Flex插件BlazeDS信息
5。在服务器中部署后台java项目
在Flex前台必须配置信息
6。在将前台项目的路径指向的Flex build Path为:后项目中swf目录;
输入 Main fold:src
输入output foldD:\workspaces\apache-tomcat-6.0.18\webapps\DataService\swf
7 。在flex前台页面使用RemoteObject访问数据信息
<mx:RemoteObject id="ro" destination="productService" endpoint="http://localhost:8090/FlexRemoteObject/messagebroker/amf" >
<mx:method name="getProducts" result="resultHandler(event)" fault="faultHandler(event)"/>
</mx:RemoteObject>
必须设置destination属性值暴露的服务的名称在romote-config.xml存在的destination名称
同时endpoint的属性值为:"http://ip:端口/项目上下文/messagebroker/amf表示默认的名称messagebroker/amf其中messagebroker为Web.xml配置的名称:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>BlazeDS</display-name>
<description>BlazeDS Application</description>
<!-- Http Flex Session attribute and binding listener support -->
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- MessageBroker Servlet -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!---服务映射名称--->
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<!-- for WebSphere deployment, please uncomment -->
<!--
<resource-ref>
<description>Flex Messaging WorkManager</description>
<res-ref-name>wm/MessagingWorkManager</res-ref-name>
<res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
-->
</web-app>
源代码如下: