user1858867
user1858867

Reputation: 11

Java /Groovy -Print the name of the browser , the request came from

in my controller (i am using grails MVC framework) , i want to print the name of browser from which the request has come.

I tried java code :

 String userAgent = request.getHeader("user-agent")
 println ("userAgent -->"+userAgent)

it prints

Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.91 Safari/537.11

i am using Google Chrome,

how to get the exact browser , from where the request has come..?

Upvotes: 1

Views: 1616

Answers (1)

The user agent header is all you got, so you'll have to parse that string to get the exact browser.

In your case, your user agent string will tell us that you're running Google Chrome version 23 (identified by Chrome/23.0.1271.91) on Windows XP 32-bits (identified by Windows NT 5.1).

The easiest way to parse the user agent is to use an already existing library and let it do it for you, one such library is the Java library for user-agent information.

Upvotes: 2

Related Questions