Browser Detection using java/Java EE

11,319

Since the user agent data is extremely sensitive to changes and you'd like to delegate the maintenance of the data to a 3rd party, consider to use a public webservice like http://user-agent-string.info. They also have a Java example for the XML-RPC service.

You can obtain the user agent of the current request using HttpServletRequest#getHeader().

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

Use that as parameter for the webservice.


That said, if you actually have compatibility problems in the HTML/CSS/MSIE area, you should really consider conditional comments. If in JS area, use feature detection. You should not rely on the user agent and certainly not in the server side. Consider posting a new question about the problem for which you thought that sniffing the user agent in the server side is the solution. You'll get much better suited answers.

Share:
11,319
An Object
Author by

An Object

I am an Object of my own Class

Updated on June 08, 2022

Comments

  • An Object
    An Object about 2 years

    In order to achieve browser compatibility in an application I am in need of a Java class/Bean/Jar which will return the following information:

    • current browser of user
    • its name
    • version
    • the OS of the user

    Any thought on this will be really helpful. This should work well in latest versions of all the modern browsers such as Chrome, Safari and Opera. How can I solve this best?