flex通过java后台获取ip和pcname示例代码

在***DAOImpl.java中的代码如下
复制代码 代码如下:

public String getCompuName()
{
Map 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前台代码
复制代码 代码如下:


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()">

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());
}
]]>












你可能感兴趣的:(flex通过java后台获取ip和pcname示例代码)