通过 Java servlet 检测操作系统或计算机名称

发布于 2024-09-01 18:24:58 字数 161 浏览 4 评论 0原文

我有一个在 Windows 计算机上开发的 Java Web 应用程序,并将部署在 Unix 计算机上。

两者的一些文件路径设置和权限详细信息有所不同(我无法更改此设置)。有没有某种方法可以通过检测操作系统或计算机名称来检测应用程序所在的机器(这只是两种机器之一),以便我可以使用适当的设置。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

書生途 2024-09-08 18:24:58

计算机名称和操作系统名称是两个不同的属性,用于获取计算机名称使用

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

和获取操作系统名称使用

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

Abdul Khaliq

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

闻呓 2024-09-08 18:24:58

您可以用来

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

了解操作系统名称。

请访问 https://docs 获取更多信息。 oracle.com/javase/1.5.0/docs/api/java/lang/System.html

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.

小嗷兮 2024-09-08 18:24:58

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

You can use System.getProperty("os.name")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文