The following code should get you started... One of the headers outputted
in this snippit is "User-Agent" so you can parse the string to get what you
are after. I use it in a servlet for debugging purposes so out is an
instance of java.io.PrintWriter from the code PrintWriter out =
response.getWriter(); and response is an instance of interface
javax.servlet.HttpServletResponse.

            Enumeration enum = request.getHeaderNames();
            if (enum.hasMoreElements()) {
                out.println("<H1>Request headers</H1>");
                out.println("<PRE>");
                while (enum.hasMoreElements()) {
                    String strName = (String)enum.nextElement();
                    out.println(" " + strName + ": " + request.getHeader(strName));
                }
                out.println("</PRE>");
            }

The output will look something like the following:

Request headers
 Accept: application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, 
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/pdf, */*
 Referer: http://localhost:7001/webiqy7001_agf.html
 Accept-Language: en-ca
 Content-Type: application/x-www-form-urlencoded
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
 Host: localhost:7001
 Content-Length: 146
 Connection: Keep-Alive
 Cache-Control: no-cache

HTH,
Greg.





"Spencer W. Thomas" <[EMAIL PROTECTED]> on 2002/08/20 11:01:12 AM

Please respond to "JDJList" <[EMAIL PROTECTED]>

To:   "JDJList" <[EMAIL PROTECTED]>
cc:

Subject:  [jdjlist] Browser detection on server side


I'm looking for code that will reliably extract the following
information from the USER_AGENT string, as seen by a web server:

Browser type (at least MSIE, Netscape, Mozilla) and version.
OS Platform (e.g., PC, Unix, Macintosh) and version
(Win95/98/Me/2K/NT/XP, Mac OS9/OSX, etc.)

I've got some code, it needs to be updated, and I figured "someone must
have written this."  I found this package,
http://dhtmlkitchen.com/java/uacheck/index.jsp (Click "Download" tab for
Java code), which is close, but doesn't give me the browser version
(except for IE).

Thanks.

=Spencer



To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm







To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to