springmvc与flex集成

0、项目结构:springmvc作为服务端,flex作为客户端,两个模块。
1、下载blazeds-spring.war,解压,把WEB-INF下的lib复制到spring项目中的WEB-INF/lib中,把flex文件夹复制到WEB-INF下。
2、web.xml中新增servlet-mapping:

    spring
    /messagebroker/*
 
3、修改spring的servlet文件,增加messagebroker:


    
    
    
    
 
4、新建controller代码如下:
package com.ztesoft.hj;import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Controller;@Controller("flexController")
@RemotingDestination(value = "flexController", channels = "my-amf")
public class FlexController {
    @RemotingInclude
    public String getHello(String str) {
        return "hello, " + str;
    }
}
 
5、flex端页面加入romoteObject:

    
 
6、定义成功回调函数和失败回调函数:
private function remoteObject_resultHandler(event:ResultEvent):void {
    Alert.show(event.result.toString());
}
private function remoteObject_faultHandler(event:FaultEvent):void {
    Alert.show(event.fault.toString());
}
 
7、定义按钮,调用函数:
private function button1_clickHandler(event:MouseEvent):void {
    remoteObject.getHello("flex");
}
 
示例代码:http://download.csdn.net/detail/kevin19900306/9796532

你可能感兴趣的:(Java,Web)