題外話:如果用EditPlus作為編輯器的話如果保存的格式默認為unicode的話那麼在裡面寫中文用resin作為應用服務器的話就可能出現報500 Servlet錯誤哦!主要是因為編碼的問題!
所以要注意好頁面的編碼問題!有時間我得作一個專題專門來討論一下有關JSP中編碼的問題哦!
題外話二:研究如何讀Linux的服務器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;
}
}