当前页面: 开发资料首页 → JSP 专题 → java开发之Flash remoting调用servlet
摘要: 在安装好后,打开jrun4的管理页面,进入页面之后你会看到jrun已经创建好了3个服务器,分别是admin,default和samples,我们使用的服务器为default。
服务器: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中加入以下的标记:
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);
}