以下是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()%>]'/>

本文介绍了一种使用Flex和JSP技术结合的方式获取客户端IP地址的方法。通过定义mxml文件中的HTTPService组件调用JSP页面实现数据交互,JSP页面负责返回客户端IP地址的XML数据。
879

被折叠的 条评论
为什么被折叠?



