Flex端访问servlet 类

package com.boco.smp.servlet
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.controls.*;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;

	public class J2eeServer extends EventDispatcher
	{
		public function J2eeServer(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		 public function sendRequest(time:String="",justUnit:String="",department:String="",eventType:String=""):void
        {
            var httpObject:HTTPService = new HTTPService();
            
            httpObject.resultFormat = "text";
            
            //httpObject.url = "http://localhost:8080/FlexSample/SampleServlet?locale="+locale;
            //http://localhost:8080/zcTopology/zcTopology.html
            httpObject.url = "http://localhost:8080/zcTopology/SampleServlet?time="+time+"&justUnit="+justUnit+"&department="+department+"&eventType="+eventType;
            
            var responder:mx.rpc.Responder = new mx.rpc.Responder(onSuccess, onFault);
            
            var call:AsyncToken = httpObject.send();
            
            call.addResponder(responder);
            
        }
        
        
        private function onSuccess(event:ResultEvent):void
        {
            //Alert.show("invoke javaServlet Success");
            this.dispatchEvent(event);   
        }
        
		
		private function onFault(event:FaultEvent):void
        {
            trace("communication failed!");
            this.dispatchEvent(event); 
        } 
		
	}
}

你可能感兴趣的:(servlet)