Q:

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.

A:

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

A:

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.

