flex通过java后台获取ip和pcname示例代码
程序员文章站
2022-03-21 23:30:39
在***daoimpl.java中的代码如下 复制代码 代码如下: public string getcompuname() { map
在***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>