Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Detection using java/Java EE

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?

like image 602
An Object Avatar asked Aug 06 '10 19:08

An Object


1 Answers

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.

like image 60
BalusC Avatar answered Oct 03 '22 10:10

BalusC