flex通过java后台获取ip和pcname示例代码
编程学习 2021-07-05 11:32www.dzhlxh.cn编程入门
这篇文章主要介绍了flex通过java后台获取ip和pcname的具体实现,需要的朋友可以参考下
在***DAOImpl.java中的代码如下
public String getCompuName()
{
Map<String, String> map = System.getenv() ;
String computerName = map.get("COMPUTERNAME");// 获取计算机名
return computerName;
}
public String getIp()
{
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
String ip = addr.getHostAddress().toString();//获得本机IP
return ip;
}
需要引入
import java.util.Map;
import java.net.InetAddress;
import java.net.UnknownHostException;
flex前台代码
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:supportClasses="com.esri.ags.skins.supportClasses.*" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function init():void
{
IPandPcname.getCompuName();
IPandPcname.getIp();
}
public function IPandPcname_faultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
public function getCompuName_Handler(event:ResultEvent):void
{
Alert.show(event.result.toString());
}
public function getIp_Handler(event:ResultEvent):void
{
Alert.show(event.result.toString());
}
]]>
</fx:Script>
<s:layout>
<supportClasses:AttachmentLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<mx:RemoteObject id="IPandPcname" destination="systemConfAction" fault="IPandPcname_faultHandler(event)">
<mx:method name="getCompuName" result="getCompuName_Handler(event)" />
<mx:method name="getIp" result="getIp_Handler(event)" />
</mx:RemoteObject>
</fx:Declarations>
</s:Application>
代码如下:
public String getCompuName()
{
Map<String, String> map = System.getenv() ;
String computerName = map.get("COMPUTERNAME");// 获取计算机名
return computerName;
}
public String getIp()
{
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
String ip = addr.getHostAddress().toString();//获得本机IP
return ip;
}
需要引入
代码如下:
import java.util.Map;
import java.net.InetAddress;
import java.net.UnknownHostException;
flex前台代码
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:supportClasses="com.esri.ags.skins.supportClasses.*" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function init():void
{
IPandPcname.getCompuName();
IPandPcname.getIp();
}
public function IPandPcname_faultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
public function getCompuName_Handler(event:ResultEvent):void
{
Alert.show(event.result.toString());
}
public function getIp_Handler(event:ResultEvent):void
{
Alert.show(event.result.toString());
}
]]>
</fx:Script>
<s:layout>
<supportClasses:AttachmentLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<mx:RemoteObject id="IPandPcname" destination="systemConfAction" fault="IPandPcname_faultHandler(event)">
<mx:method name="getCompuName" result="getCompuName_Handler(event)" />
<mx:method name="getIp" result="getIp_Handler(event)" />
</mx:RemoteObject>
</fx:Declarations>
</s:Application>
上一篇:Flex弹出窗口请求Action函数示例
下一篇:flex内嵌html网页示例代码