我能够从 as3 获取数据到 servlet 成功读取它,但无法从 servlet 发送回 as3。
下面是 AS3 代码。应用程序加载到 Tomcat 服务器上。
var request:URLRequest = new URLRequest("http://localhost:8080/Demo/UserDataControllerServlet");
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
add_txt.text ="http://localhost:8080/Demo/UserDataControllerServlet";
var _vars:URLVariables = new URLVariables();
_vars.emailId = "abc@gmail.com";
_vars.phoneNumber = "9898989898";
_vars.userAddress = "abc";
_vars.userName = "abc";
_vars.vendorAddress = "abc";
_vars.vendorName = "abc";
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
loader.load(request);
add_txt.text ="already sent........................";
private function onSecurityError(event:SecurityErrorEvent):void {
add_txt.text ="security error ........................";
}
这应该在响应返回到 as3 后执行。
private function handleComplete(event:Event):void {
add_txt.text ="in the response function";
var loader:URLLoader = URLLoader(event.target);
trace("Message: " + loader.data);
add_txt.text = "========="+loader.data;
}
private function onIOError(event:IOErrorEvent):void {
add_txt.text = "Error loading URL.";
trace("Error loading URL.");
this.parent.removeChild(this);
}
下面是 servlet 代码: 我能够从请求中读取数据,但是在 out.write 和 out.close 之后响应不会返回到 as3。我尝试删除 out.close() 但即使这样也无济于事。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String emailId = request.getParameter("emailId");
String phoneNumber = request.getParameter("phoneNumber");
String userAddress = request.getParameter("userAddress");
String userName = request.getParameter("userName");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("Hello");
out.close();
}
你能帮我解决这个在 as3 中没有接收到数据的问题吗?