本文共 1216 字,大约阅读时间需要 4 分钟。
以下是mxml 和jsp文件:
<? xml version = " 1.0 " encoding = " utf-8 " ?> < mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " layout = " vertical " > < mx:Script ><! [CDATA[ import mx.rpc.events.ResultEvent; [Bindable] private var _sClientIPUrl:String = " http://localhost:8600/myip.jsp " ; /**/ /** Runs on creationComplete */ private function initApp(): void ... { dsClientIP.send(); //invokes the data service call } /**/ /** called by the result event of the data service call */ private function onResult(oEvent:ResultEvent): void ... { var xmlResult:XML = XML(oEvent.result); //get the result as XML //trace(xmlResult); var sIp:String = xmlResult.@clientIP; //get the attribute value //trace(sIp); lbIP.text = sIp; //display it } ]] ></ mx:Script > < mx:Label id = " lbIP " fontSize = " 26 " /> < mx:Button x = " 20 " y = " 20 " label = " send " click = " initApp(); " /> < mx:HTTPService id = " dsClientIP " url = " {_sClientIPUrl} " result = " onResult(event) " resultFormat = " e4x " /> </ mx:Application >
myip.jsp:
<% ... @ page contentType="text/xml; charset=UTF-8" %> <? xml version="1.0" encoding="utf-8" ?> < systemdata clientIP ='<%=request.getRemoteHost()% > [ <% = request.getRemoteAddr() %> ]'/> 转载地址:http://nbfmb.baihongyu.com/