Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with request.getHeader("User-Agent")

843842Aug 14 2008 — edited Aug 14 2008
Hi,

I need to get user-agent header to check what type of browser is used. With command:
request.getHeader("User-Agent")
I got not whole information. For example the result is:
Mozilla/4.0 (Mac OS X 10.5.4) Java/1.5.0_13,

when it shoud look like:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-GB; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16

Using:
Enumeration headerNames = request.getHeaderNames();
for(Enumeration<String> e = request.getHeaderNames() ;headerNames.hasMoreElements();){
  StringBuffer buff = new StringBuffer();
  String next = e.nextElement();
  for(Enumeration<String> ee = request.getHeaders(next); ee.hasMoreElements();){
    buff.append(ee.nextElement());
    buff.append(" ");
  }
  System.out.println(next + "\t" + new String(buff));
}
I think I checked everything what I can get from request headers... I got this:
content-type application/octet-stream
cache-control no-cache
pragma no-cache
user-agent Mozilla/4.0 (Mac OS X 10.5.4) Java/1.5.0_13
host localhost:8080
accept text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
connection keep-alive
content-length 262

So is there any way to get whole information about user-agent?? I can do this at servlet and in applet.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2008
Added on Aug 14 2008
1 comment
280 views