獲取計算機全名
阿新 • • 發佈:2018-12-02
String path = request.getContextPath(); //獲取專案名
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//獲取全路徑
//獲取配置檔案中的值
public String getUrl(){
String strofficeApps=null ;
Properties pro=new Properties();
try {
pro.load(getClass().getResourceAsStream("/spring-context.properties"));
strofficeApps= pro.getProperty("strofficeapps");
} catch (Exception e) {
e.printStackTrace();
}
return strofficeApps;
}
//獲取計算機全名稱
public String getServerName() {
String name =null;
InetAddress ServerIPaddress=null;
try {
ServerIPaddress=InetAddress.getLocalHost();
name=ServerIPaddress.getCanonicalHostName();
}
catch (UnknownHostException e) {
}
return name;
}