服务器: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:
1.在C:jrun4serversdefaultdefault-eardefault-warWEB-INF的web.xml中加入以下的标记:
<servlet> <servlet-name>MyServlet</servlet-name> <display-name>MyServlet</display-name> <description>This is a servlet of H2O</description> <servlet-class>MyServlet</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;
gatewayConnnection = NetServices.createGatewayConnection();
FlashtestService = gatewayConnnection.getService("",this);
FlashtestService.MyServlet();
function MyServlet_Result(result){
users= result; trace(users);
}
ok! 就是这么简单,但可花费了我不少的心血呀,希望大家珍惜,也祝大家能一次搞定!