如何获取操作系统和浏览器等客户端信息 [英] How can I get client information such as OS and browser

查看:201
本文介绍了如何获取操作系统和浏览器等客户端信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSP,Servlet来开发我的Web应用程序。

I'm using JSP, Servlet to develop my web application.

我想获取客户端信息,例如:操作系统,浏览器,分辨率,......每当客户使用我的网站时。

I want to get client information such as: operation system, browser, resolution, ... whenever a client is using my website.

推荐答案

您最好的选择是User-Agent标头。你可以在JSP或Servlet中得到它,

Your best bet is User-Agent header. You can get it like this in JSP or Servlet,

String userAgent = request.getHeader("User-Agent");

标题如下所示,

User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13

它提供有关浏览器的详细信息。然而,它几乎是免费的格式,所以很难解读每一个。您只需要弄清楚您将支持哪些浏览器并为每个浏览器编写解析器。当您尝试识别浏览器的版本时,请始终先检查更新的版本。例如,IE6用户代理可能包含IE5以实现向后兼容。如果您先检查IE5,IE6也将被归类为IE5。

It provides detailed information on browser. However, it's pretty much free format so it's very hard to decipher every single one. You just need to figure out which browsers you will support and write parser for each one. When you try to identify the version of browser, always check newer version first. For example, IE6 user-agent may contain IE5 for backward compatibility. If you check IE5 first, IE6 will be categorized as IE5 also.

您可以从此网站获得所有用户代理值的完整列表,

You can get a full list of all user-agent values from this web site,

http://www.user-agents.org/

使用User-Agent,您可以确定浏览器的确切版本。您可以在操作系统上获得一个非常好的想法,但您可能无法区分同一操作系统的不同版本,例如,Windows NT和2000可能使用相同的用户代理。

With User-Agent, you can tell the exact version of the browser. You can get a pretty good idea on OS but you may not be able to distinguish between different versions of the same OS, for example, Windows NT and 2000 may use same User-Agent.

决议没有任何意义。但是,您可以在AJAX调用中使用Javascript获取此信息。

There is nothing about resolution. However, you can get this with Javascript on an AJAX call.

这篇关于如何获取操作系统和浏览器等客户端信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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