欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Flex 向 Java 調用
前幾天由于搞項目需要用到Flex 向 Java 服務(wù)通信傳輸數據,搞了好大半天灰常痛苦,在網(wǎng)上的片段很少,現在我整合一下。希望對以后要用到的童靴有一點(diǎn)用處。我項目里面傳輸的是二進(jìn)制數據。Flex 向 Java servlet通信,Java服務(wù)端再返回數值到Flex客戶(hù)端。童鞋們先要下載Flex 的兩個(gè)包(flex-messaging-common.jar,flex-messaging-core.jar)放置Java工程的lib下。

代碼片段(6)

[文件] AllServlet.java ~ 3KB 下載(37)

package cn.tianqi.game.servlet;import java.io.DataOutputStream;import java.io.IOException;import java.util.Collection;import java.util.List;import java.util.Map;import java.util.zip.DeflaterOutputStream;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.tianqi.game.action.util.AmfDataServlet;import cn.tianqi.game.action.util.Configuration;import cn.tianqi.game.action.view.MapBean;import cn.tianqi.game.action.view.ResourceBean;import cn.tianqi.game.action.view.SysBean;import cn.tianqi.game.action.vo.ResourceVo;import flex.messaging.io.SerializationContext;import flex.messaging.io.amf.Amf3Output;public class AllServlet extends HttpServlet {	private static final long serialVersionUID = 1L;	private AmfDataServlet amfData=new AmfDataServlet();	private ResourceBean catBean=ResourceBean.getInstance();	private MapBean mapBean=MapBean.getInstance();	private SysBean sysBean=SysBean.getInstance();	public AllServlet() {		super();	}	public void destroy() {		super.destroy(); // Just puts "destroy" string in log		// Put your code here	}	public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		doPost(request, response);	}	@SuppressWarnings("unchecked")	public void doPost(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		request.setCharacterEncoding("UTF-8");		response.setContentType("text/html;charset=utf-8");				Map map=(Map)amfData.getObj(request.getContentLength(), request.getInputStream());		String method=String.valueOf(map.get("method"));		if(method.equals(Configuration.SYS_INIT)){			Collection coll=catBean.resourceCat().values();//所有素材資源數據			Collection coll2=catBean.mapResource().values();//所有地圖素材資源數據			Collection coll3=mapBean.selectAllMap().values();//所有地圖資源數據			List<ResourceVo> coll4=catBean.selectALLRes();//所有資源表數據			send(response, sysBean.sysInit(coll,coll2,coll3,coll4));		}else if(method.equals(Configuration.CAT_RESOURCE)){			send(response, catBean.resourceCat().values());		}else if(String.valueOf(map.get("method")).equals(Configuration.MAP_RESOURCE)){			send(response, catBean.mapResource().values());		}else if(method.equals(Configuration.CAT_RESOURCE_ADD)){			Map cat=(Map)map.get("data");			send(response, catBean.saveResourceCat(cat));		}else if(method.equals(Configuration.MAP_RESOURCE_DATA)){			send(response, mapBean.selectAllMap().values());		}else if(method.equals(Configuration.MAP_DATA_SAVE)){			Map mds=(Map)map.get("data");			send(response, mapBean.saveMap(mds));		}	}		protected void send(HttpServletResponse response,Object obj) throws IOException{		Amf3Output amf3=new Amf3Output(new SerializationContext());		DeflaterOutputStream stream = new DeflaterOutputStream(new DataOutputStream(response.getOutputStream()));		amf3.setOutputStream(stream);		amf3.writeObject(obj);        stream.finish();	}	public void init() throws ServletException {		// Put your code here	}}

[文件] AmfDataServlet.java ~ 2KB 下載(28)

package cn.tianqi.game.action.util;import java.io.ByteArrayInputStream;import java.io.DataInputStream;import java.io.IOException;import java.io.InputStream;import javax.servlet.ServletInputStream;import flex.messaging.io.SerializationContext;import flex.messaging.io.amf.Amf3Input;public class AmfDataServlet {		/**	 * 解析HttpServletRequest上傳的二進(jìn)制數據	 * @param contentLength	上傳的數據總長(cháng)度(request.getContentLength())	 * @param stream	上傳的數據(request.getInputStream())	 * @return Object	 */	public Object getObj(int contentLength, ServletInputStream stream) {		Object obj = null;		DataInputStream dis = new DataInputStream(stream);		byte[] by = new byte[contentLength];		try {			int bytesRead = 0, totalBytesRead = 0;			while (totalBytesRead < contentLength) {				bytesRead = dis.read(by, totalBytesRead, contentLength);				totalBytesRead += bytesRead;			}			Amf3Input amf = new Amf3Input(new SerializationContext());			InputStream is = new ByteArrayInputStream(by);			amf.setInputStream(is);						obj = amf.readObject();		} catch (ClassNotFoundException e) {			e.printStackTrace();		} catch (IOException e) {			e.printStackTrace();		}		return obj;	}		/**	 * 解析byte[]轉成Object	 * @param bytes 數據	 * @return Object	 */	public Object getObj(byte[] bytes){		Object obj=null;		try {			Amf3Input amf = new Amf3Input(new SerializationContext());			InputStream is = new ByteArrayInputStream(bytes);			amf.setInputStream(is);			obj=amf.readObject();		} catch (ClassNotFoundException e) {			e.printStackTrace();		} catch (IOException e) {			e.printStackTrace();		}		return obj;	}}

[文件] Servlet.as ~ 2KB 下載(24)

package cn.tianqi.game.servlet{	import flash.net.URLLoader;	import flash.net.URLLoaderDataFormat;	import flash.net.URLRequest;	import flash.net.URLRequestMethod;	public class Servlet	{		private static var servlet:Servlet=null;		private var httpUrl:String="http://192.168.1.101:8080/manager/";		//private var httpUrl:String="http://localhost:8080/manager/";				public function allServlet():URLRequest		{			var urlRequest:URLRequest=new URLRequest(httpUrl+"AllServlet");			urlRequest.contentType = 'applicatoin/octet-stream';			urlRequest.method=URLRequestMethod.POST;			return urlRequest;		}//		public function resourceCatServlet():URLRequest//		{//			var urlRequest:URLRequest=new URLRequest(httpUrl+"CatInfoServlet");//			urlRequest.contentType = "applicatoin/octet-stream";//			urlRequest.method=URLRequestMethod.POST;//			return urlRequest;//		}				public function fileUpload():URLRequest		{			var urlRequest:URLRequest=new URLRequest(httpUrl+"FileUpload");			return urlRequest;		}		//		public function saveResourceCat():URLRequest//		{//			var urlRequest:URLRequest=new URLRequest(httpUrl+"ResourceAddServlet");//			urlRequest.method=URLRequestMethod.POST;//			return urlRequest;//		}		//		public function mapResource():URLRequest//		{//			var urlRequest:URLRequest=new URLRequest(httpUrl+"MapResourceServlet");//			urlRequest.method=URLRequestMethod.POST;//			return urlRequest;//		}		//		public function saveMapResource():URLRequest//		{//			var urlRequest:URLRequest=new URLRequest(httpUrl+"MapResourceDataServlet");//			urlRequest.method=URLRequestMethod.POST;//			return urlRequest;//		}				public static function getServlet():Servlet		{			if(servlet==null)			{				servlet=new Servlet();			}			return servlet;		}			}}

[文件] flex-messaging-common.jar ~ 92KB 下載(53)

[文件] flex-messaging-core.jar ~ 599KB 下載(49)

[代碼] [Java]代碼

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">	<mx:Script>		<![CDATA[			import cn.tianqi.game.servlet.Servlet;						import mx.collections.ArrayCollection;						private var loader:URLLoader=null;			private var v:URLVariables=null;			private var urls:URLRequest=null;			protected function mapResource_clickHandler(event:MouseEvent):void			{				loader=new URLLoader();				loader.dataFormat = URLLoaderDataFormat.BINARY;				loader.addEventListener(Event.COMPLETE, loaderHandler);  				loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loaderHandler);  				loader.addEventListener(IOErrorEvent.IO_ERROR, loaderHandler);				//				v=new URLVariables();//				v.type=2;								//urls=Servlet.getServlet().mapResource();								urls=Servlet.getServlet().allServlet();				//urls.contentType = 'applicatoin/octet-stream';								var obj:Object=new Object();				obj.n="南泥灣";				obj.w=201;				obj.h=150;				obj.ms="101010100000001111000011111000000000";								var dt:ByteArray=new ByteArray();				dt.writeByte(100);								obj.dt=dt;								var obj1:Object=new Object();				obj1.method="mapDataSave";				obj1.data=obj;								var byteArr:ByteArray=new ByteArray();				byteArr.writeObject(obj1);								urls.data=byteArr;				//				urls.data=v;								loader.load(urls);			}						protected function loaderHandler(event:Event):void			{				trace(event.type);				switch(event.type){					case Event.COMPLETE:						var byte:ByteArray = event.target.data as ByteArray;						byte.uncompress();						var obj:Object = byte.readObject();						var arr:ArrayCollection=obj as ArrayCollection;						break;				}			}		]]>	</mx:Script>	<mx:Button id="mapResource" label="點(diǎn)擊我" click="mapResource_clickHandler(event)"/></mx:Application>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
flex 強大的navigateToURL方法
android 封裝抓取網(wǎng)頁(yè)信息的實(shí)例代碼
JFreeChart在JSP中的應用實(shí)例
jsp文件下載完整方法
申精--flex4圖表Chart導出圖片功能實(shí)現詳解--菜鳥(niǎo)級詳解
更新之后出現The import java.io cannot be resolved錯誤
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久