`您好,
我试图在我的servlet过滤器中获取用户的浏览器信息。我使用了一个简单的代码,见下文。
String userAgent = request.getHeader("User-Agent");
用户正在使用Google Chrome,上面的代码打印在下面。
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
它打印了所有主要浏览器的名称,而不是在应用程序运行后获取。这有什么不对?
答案 0 :(得分:0)
这里没有错。
例如,让我们考虑返回的字符串是
Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 41.0.2228.0 Safari / 537.36
然后说明是
ChromeChrome 41.0.2228.0
Mozilla ==>
MozillaProductSlice. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore
5.0 ==> Mozilla version
Windows NT 6.1 ==> Operating System Windows 7
AppleWebKit ==> The Web Kit provides a set of core classes to display web content in windows
537.36 ==> Web Kit build
KHTML ==> Open Source HTML layout engine developed by the KDE project
like Gecko ==> like Gecko...
Chrome Name ==> Chrome
41.0.2228.0 ==> Chrome version
Safari ==> Based on Safari
537.36 ==> Safari build
Description: Free open-source web browser developed by Google.
Chromium is the name of the open source project behind Google Chrome, released under the BSD license.
您可以在以下链接中找到更多信息
http://www.useragentstring.com/pages/Chrome/
点击页面上的每个链接以获取更多信息