简体   繁体   中英

Detecting operating system or computer name through a Java servlet

I have a Java web app that I develop on a Windows machine and will deploy on a Unix machine.

There are some file path settings and permissions details that differ on the two (and there is nothing I can do to change this). Is there some way of detecting which machine the app is sitting on (it's only one of two), either by detecting the operating system or the computer's name so I can then using the appropriate settings.

Computer name and OS name are two different properties to get computer name use

String computername=InetAddress.getLocalHost().getHostName();
      System.out.println(computername);

and to get os name use

java.lang.System.getProperty("os.name")

Abdul Khaliq

You can use

java.lang.System.getProperty("os.name")

to know the operating system name.

Get more info at https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html .

您可以使用System.getProperty("os.name")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM