How to get the exact name and version of the client browser in Spring MVC?

I am working on a Spring MVC application and I need to access the name and version of the client browser.

I have an HttpServletRequest instance in my action as a parameter and use the request.getHeader("User-Agent") method, but this returned Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko on the Internet explorer 9.

I need the exact number and version. Are there any tools for this?

+6
source share
1 answer

Confirmation that the user agent is unsafe. However, in the absence of other methods, you should parse the user-agent header, which is actually not so simple, since the number of combinations is overwhelming. If you do not want to quit your own, I would suggest

http://www.bitwalker.eu/software/user-agent-utils

A source

available in

https://github.com/HaraldWalker/user-agent-utils/tree/master

use is quite simple

 UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); System.out.println(userAgent.getBrowser().getName() + " " + userAgent.getBrowserVersion()); 
+11
source

Source: https://habr.com/ru/post/981979/


All Articles