基礎(chǔ)入門:淺談小偷程序之Java

字號(hào):

題外話一:如果用EditPlus作為編輯器的話如果保存的格式默認(rèn)為unicode的話那么在里面寫中文用resin作為應(yīng)用服務(wù)器的話就可能出現(xiàn)報(bào)500 Servlet錯(cuò)誤哦!主要是因?yàn)榫幋a的問題!
    所以要注意好頁面的編碼問題!有時(shí)間我得作一個(gè)專題專門來討論一下有關(guān)JSP中編碼的問題哦!
    題外話二:研究如何讀LINUX的服務(wù)器IP
    import java.net.InetAddress;
    import java.net.NetworkInterface;
    import java.net.SocketException;
    import java.util.Enumeration;  
    public class GetIp {
    public static void main(String[] args){
    String ip = null;
    GetIp test = new GetIp();
    try{
    ip = test.getLocalSiteIP();
    }catch(Exception e){
    System.out.print(e.toString());
    }
    System.out.print(ip);
    }
    private String getLocalSiteIP() throws Exception {
    String siteString = "";
    Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
    while (netInterfaces.hasMoreElements()) {
    NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
    InetAddress ip = (InetAddress) ni.getInetAddresses().nextElement();
    if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() &&
    ip.getHostAddress().indexOf(":") == -1) {
    siteString = ip.getHostAddress();
    }
    }
    return siteString;
    }
    }