服务器:jrun4
组件:flash remoting components as2.0
软件:flash mx 2004 pro
在安装好后,打开jrun4的治理页面,进入页面之后你会看到jrun已经创建好了3个服务器,分别是admin,default和samples,我们使用的服务器为default,对与flash remoting的相关用法可参照lwanchen的flashremoting实践(三)-hello world for Java:http://www.riacn.com/web/showArticle.ASP?id=111
1.在C:\jrun4\servers\default\default-ear\default-war\WEB-INF的web.XML中加入以下的标记:
<servlet <servlet-nameMyServlet</servlet-name <display-nameMyServlet</display-name <descriptionThis is a servlet of H2O</description <servlet-classMyServlet</servlet-class </servlet
2.将编译好的MyServlet.class这个servlet放在classes
MyServlet.java为
import javax.servlet.*;
import java.io.IOException;
import java.util.List;
public class MyServlet implements Servlet {
private String message = null;
public void init(ServletConfig config) throws ServletException {
message = "Hello from MyServlet";
}
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
request.setAttribute("FLASH.RESULT", message);
}
public String getServletInfo() {
return "A test servlet.";
}
public ServletConfig getServletConfig() {
return null;
}
public void destroy() {
message = null;
}
}
3.在flash mx 2004 pro中的调用方法为:
import mx.remoting.NetServices;
import mx.remoting.Connection;
NetServices.setDefaultGatewayUrl("http://localhost:8100/flashservices/gateway";);
gatewayConnnection = NetServices.createGatewayConnection();
flashtestService = gatewayConnnection.getService("",this); flashtestService.MyServlet();
function MyServlet_Result(result){
users= result; trace(users);
}
ok! 就是这么简单,但可花费了我不少的心血呀,希望大家珍惜,也祝大家能一次搞定!