java开发之Flash remoting调用servlet
2008-01-05 10:32:45 来源:WEB开发网核心提示:服务器:jrun4组件:Flash remoting components as2.0软件:flash mx 2004 PRo在安装好后,打开jrun4的治理页面,java开发之Flash remoting调用servlet,进入页面之后你会看到jrun已经创建好了3个服务器,分别是admin,default和samp
服务器: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-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("http://localhost:8100/flashservices/gateway";);
gatewayConnnection = NetServices.createGatewayConnection();
flashtestService = gatewayConnnection.getService("",this); flashtestService.MyServlet();
function MyServlet_Result(result){
users= result; trace(users);
}
ok! 就是这么简单,但可花费了我不少的心血呀,希望大家珍惜,也祝大家能一次搞定!