[thelist] jsp/java browser detect

BILL AVANT b.avant at futura.net
Mon Oct 18 14:38:44 CDT 2004


----- Original Message ----- 
From: <evolt at mccullough-net.com>
To: <thelist at lists.evolt.org>
Sent: Monday, October 18, 2004 11:08 AM
Subject: Re: [thelist] jsp/java browser detect


> What I ended up doing was writting a bean.
>
> ##############################################################
>
> package com.dynamic.logic;
>
> import java.io.Serializable;
> import javax.servlet.http.HttpServletRequest;
>
> public final class DetectBrowser implements Serializable {
>
> private HttpServletRequest request = null;
> private String useragent = null;
> private boolean netEnabled = false;
> private boolean ie = false;
> private boolean ns6 = false;
> private boolean ns7 = false;
> private boolean op = false;
> private boolean moz = false;
> private boolean ns4 = false;
>
>
> public void setRequest(HttpServletRequest req) {
> request = req;
> useragent = request.getHeader("User-Agent");
> String user = useragent.toLowerCase();
> if(user.indexOf("msie") != -1) {
> ie = true;
> } else if(user.indexOf("netscape6") != -1) {
> ns6 = true;
> } else if(user.indexOf("netscape/7") != -1) {
> ns7 = true;
> } else if(user.indexOf("opera") != -1) {
> op = true;
> } else if(user.indexOf("gecko/2004") != -1) {
> moz  = true;
> } else if(user.indexOf("mozilla/4.7") != -1) {
> ns4 = true;
> }
>
> if(user.indexOf(".net clr") != -1)
> netEnabled = true;
> }
>
> public String getUseragent() {
> return useragent;
> }
>
> public boolean isNetEnabled() {
> return netEnabled;
> }
>
> public boolean isIE() {
> return ie;
> }
>
> public boolean isNS7() {
> return ns7;
> }
>
> public boolean isNS6() {
> return ns6;
> }
>
> public boolean isOP() {
> return op;
> }
>
> public boolean isMOZ() {
> return moz;
> }
>
> public boolean isNS4() {
> return ns4;
> }
> }
>
> ##############################################################
>
> to detect the user-agent string for the various browsers, Mozilla, Firefox
and
> Netscape have very similar strings, and since I wanted to allow Mozilla
and
> Firefox, it took me more trial and error to get it right.
>
> Quoting Hassan Schroeder <hassan at webtuitive.com>:
>
> > evolt at mccullough-net.com wrote:
> > > What I have started to do is in my jsp page is to put in some browser
> > detection,
> > > I need to redirect based on what browser you have.  So for Netscape
4.7,
> > > generation 6, earlier IE versions and so on.
> > >
> > > CODE:
#################################################################
> >
> > <snip/>
> >
> > > Help :)
> >
> > with what, exactly?
> >
> > -- 
> > Hassan Schroeder ----------------------------- hassan at webtuitive.com
> > Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com
> >
> >                            dream.  code.
> >
> >
> > -- 
> >
> > * * Please support the community that supports you.  * *
> > http://evolt.org/help_support_evolt/
> >
> > For unsubscribe and other options, including the Tip Harvester
> > and archives of thelist go to: http://lists.evolt.org
> > Workers of the Web, evolt !
> >
>
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !



More information about the thelist mailing list