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

网络编程 2021-07-05 11:32www.168986.cn编程入门
这篇文章主要介绍了flex通过java后台获取ip和pame的具体实现,需要的朋友可以参考下
在DAOImpl.java中的代码如下
代码如下:

public String getCompuName()
{
Map<String, String> map = System.getenv() ;
String puterName = map.get("COMPUTERNAME");// 获取计算机名
return puterName;
}
public String getIp()
{
IAddress addr = null;
try {
addr = IAddress.getLocalHost();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
String ip = addr.getHostAddress().toString();//获得本机IP
return ip;
}

需要引入
代码如下:

import java.util.Map;
import java..IAddress;
import java..UnknownHostException;

flex前台代码
代码如下:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe./mxml/2009"
xmlns:s="library://ns.adobe./flex/spark"
xmlns:mx="library://ns.adobe./flex/mx" xmlns:supportClasses=".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
{
IPandPame.getCompuName();
IPandPame.getIp();
}
public function IPandPame_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="IPandPame" destination="systemConfAction" fault="IPandPame_faultHandler(event)">
<mx:method name="getCompuName" result="getCompuName_Handler(event)" />
<mx:method name="getIp" result="getIp_Handler(event)" />
</mx:RemoteObject>
</fx:Declarations>
</s:Application>

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by