服務器: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! 就是這麼簡單,但可花費了我不少的心血呀,希望大家珍惜,也祝大家能一次搞定!