File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Recognize the browser type    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Recognize the browser type    " Watch "Recognize the browser type    " New topic

Recognize the browser type

Rao Devata

Joined: Jul 21, 2006
Posts: 4
We are developing website. In which we want to know the from where
the request is originated. I mean whether it is a request from mobile browser or it is a request from desktop browser.
Our objective is to find out browser type and based on that forwarding the request (mobile browser request or desktop browser request) to the particular jsp page which contains the view for the particular client.

So the question is , how to find browser type. b'cos current mobiles also have html/xhtml enabled browsers. but their screen - size prohibit
to take adwantage of these languages.

Please help us..
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

All you have on the server side is the User-Agent request header.
Some browsers can be configured to spoof that value so it's not 100% reliable.

There are ways, using Javascript, to determine the browser type from the client side, which can be sent to the server in the next request via querystring or post variables.

Say the word and I'll move this thread to our HTML/Javascript forum.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
At a previous company we used a combination of the user-agent and accepts header to determine micro-browser vs browser. We used a system of pattern matching to determine the best content for the device.

As stated earlier, desktop browsers can spoof header easily. However, I am not aware of the same for microbrowsers.

There are other headers that mark the use of a micro-browser such as


to name a few. It may be a good idea, after determining the browser type and presenting the first page, to include a link to the alternate version. This would help users who are identified incorrectly.

If you decide to got the user agent route, here are a list of user-agents that can help you build and test the identification portion of your code. The list is compiled from visitor statistics on and organized by frequency.

BTW, spiders will sometimes spoof usergents when index your site.

Rashid Mayes -
I agree. Here's the link:
subject: Recognize the browser type
It's not a secret anymore!