【问题标题】:sending mac address from client pc to server pc in jsf在jsf中将mac地址从客户端pc发送到服务器pc
【发布时间】:2013-04-15 09:35:12
【问题描述】:

首先我像这样从pc客户端获取mac地址

public void getterMacAddress(){
      InetAddress ip;
    try {

        ip = InetAddress.getLocalHost();
        System.out.println("Current IP address : " + ip.getHostAddress());

        NetworkInterface network = NetworkInterface.getByInetAddress(ip);

        byte[] mac = network.getHardwareAddress();

        System.out.print("Current MAC address : ");

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mac.length; i++) {
            sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));        
        }
        System.out.println(sb.toString());
                macAddress = sb.toString();

    } catch (UnknownHostException e) {

        e.printStackTrace();

    } catch (SocketException e){

        e.printStackTrace();

    }
    }

我成功获取了mac地址,但是如何将mac地址发送到服务器?

【问题讨论】:

  • 发送到服务器是什么意思。当您在服务器上部署应用程序时,它已经存在。你只需要阅读它

标签: java jsf


【解决方案1】:

您可以将字符串作为 URL 参数传递给服务器(JSF)

myserver:port/myproject/innerpage/mac.jsf?mac=5C-AC-4C-75-44-4A

public class Bean {

@ManagedProperty(value="#{param.mac}")
private String mac;

@PostConstruct
public void init() {
    System.out.println(mac); // 5C-AC-4C-75-44-4A
}
// ...
}

也看这个问题:parameter in URL jsf2

我不建议为此目的使用 JSF。 Servlet 或 REST Web 服务 - 是一种更好的方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多