如何检测在Java小程序的浏览器和操作系统 [英] how to detect browser and OS in Java applet

查看:231
本文介绍了如何检测在Java小程序的浏览器和操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上运行良好的Safari和在Windows和Linux各种浏览器,但在Chrome和Firefox上的Macintosh问题复杂的Java小程序。为了调试,这将是非常有益的,如果Java的code可以检测和报告的浏览器,浏览器版本,操作系统,操作系统版本时出现错误。

I'm working on a complex Java applet which runs well in Safari and in various browsers on Windows and Linux but has problems on Macintosh in Chrome and Firefox. For debugging, it would be really helpful if Java code could detect and report the browser, the browser version, the OS, and the OS version when there are errors.

什么是Java检测到信息的最简单,最可靠的方法是什么?

What is the easiest and most reliable way for Java to detect that info?

这看起来不错,但需要Apache log4j的,我不知道如果我能说服团队来运行:的 HTTP://$c$c.google.com/p/user-agent-utils/

This looks good, but requires Apache log4j, and I don't know if I can convince the team to run that: http://code.google.com/p/user-agent-utils/'

我猜的Java能得到通过JavaScript的用户代理字符串,但我找不到任何好的例子code,清楚地显示了如何做到这一点。

I guess Java could get the user-agent string via JavaScript, but I can't find any good example code that clearly shows how to do that.

推荐答案

您可以得到由<一个必要的操作系统信息href=\"http://download.oracle.com/javase/6/docs/api/java/lang/System.html#getProperty%28java.lang.String%29\"相对=nofollow> 系统#的getProperty() 如下:

You can get the necessary OS information by System#getProperty() as follows:

String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
String osArch = System.getProperty("os.arch");
String javaRuntimeVersion = System.getProperty("java.runtime.version");

对于其他人,检查的 系统#的GetProperties()

用户代理字符串不是那么重要。这一切都在同一个JVM和操作系统之后。无论如何,你可以让服务器端编程语言从目前的请求头得到它,并把它作为一个&LT;对象&gt; &LT;小程序&GT; 参数的小程序。这是一个使用JSP / EL的例子:

The user agent string is not so relevant. It's after all the same JVM and OS. Regardless, you could let the server side programming language get it from the current request headers and pass it as an <object> or <applet> parameter to the applet. Here's an example using JSP/EL:

<param name="userAgent" value="${header['user-agent']}" />

和获得它在小程序如下:

and obtain it in the applet as follows:

String userAgent = getParameter("userAgent");

在具有手中的用户代理字符串,您可以在 HTTP找到Web服务://用户代理字符串.INFO 比谷歌code中的用户代理utils的更加有用。

Once having an user agent string at hands, you may find the webservice at http://user-agent-string.info more useful than the user agent utils at Google Code.

这篇关于如何检测在Java小程序的浏览器和操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆