Total members 9952 | Gratitudes |It is currently Sat Feb 11, 2012 2:28 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 7 posts ] 
Author Question
 Question subject: how can we get browser information in jsp?
PostPosted: Wed Oct 22, 2008 2:04 am 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:47 pm
Posts: 281
Has thanked: 0 time
Have thanks: 1 time

how can we get browser information in jsp?


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Wed Oct 22, 2008 2:04 am 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:53 pm
Posts: 229
Has thanked: 0 time
Have thanks: 0 time
Code:
String browserType=(String)request.getHeader("User-Agent");

now if you print browserType , you will get the information of browser.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Fri Oct 23, 2009 5:25 am 
Offline
Newbie
User avatar

Joined: Fri Oct 23, 2009 5:16 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time
Code:
private String getBrowserType(String currValue){
String browser = new String("");
String version = new String("");
if(currValue != null ){
if((currValue.indexOf("MSIE") == -1) && (currValue.indexOf("msie") == -1)){
browser = "NS";
int verPos = currValue.indexOf("/");
if(verPos != -1)
version = currValue.substring(verPos+1,verPos + 5);
}
else{
browser = "IE";
String tempStr = currValue.substring(currValue.indexOf("MSIE"),currValue.length());
version = tempStr.substring(4,tempStr.indexOf(";"));

}

}
System.out.println(" now browser type is " + browser +" " + version);

return browser + " " + version;

}

_________________
http://checkbrowser.info


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Mon Nov 02, 2009 1:57 pm 
Offline
Newbie
User avatar

Joined: Mon Nov 02, 2009 1:42 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time
For the browser part you need to parse the request's User-Agent section.

Code:

String browserType 
request.getHeader("User-Agent");
 


There you'll find the relevant information...
The following jsp will output your ip address and user-agent:

Your user-agent is:
Code:
<%=request.getHeader("user-agent")%> 
 

Your IP address is:
Code:

 
<%=request.getRemoteAddr()%> 
 


To find out what browser and/or OS the user is using, parse the user-agent header.
For example:
Code:
<%
String userAgent request.getHeader("user-agent");
if (
userAgent.indexOf("MSIE") > -1) {
  
out.println("Your browser is Microsoft Internet Explorer<br/>");
}
  


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Mon Nov 02, 2009 3:15 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 57 time
thanks for the addition .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Tue Sep 27, 2011 11:25 am 
you can user this function for get browser name and version

Code:
<%!

public String  getBrowserInfo( String Information )
   {
          String browsername = "";
          String browserversion = "";
          String browser = Information  ;
          if(browser.contains("MSIE")){
              String subsString = browser.substring( browser.indexOf("MSIE"));
              String Info[] = (subsString.split(";")[0]).split(" ");
              browsername = Info[0];
              browserversion = Info[1];
           }
         else if(browser.contains("Firefox")){

              String subsString = browser.substring( browser.indexOf("Firefox"));
              String Info[] = (subsString.split(" ")[0]).split("/");
              browsername = Info[0];
              browserversion = Info[1];
         }
         else if(browser.contains("Chrome")){

              String subsString = browser.substring( browser.indexOf("Chrome"));
              String Info[] = (subsString.split(" ")[0]).split("/");
              browsername = Info[0];
              browserversion = Info[1];
         }
         else if(browser.contains("Opera")){

              String subsString = browser.substring( browser.indexOf("Opera"));
              String Info[] = (subsString.split(" ")[0]).split("/");
              browsername = Info[0];
              browserversion = Info[1];
         }
         else if(browser.contains("Safari")){

              String subsString = browser.substring( browser.indexOf("Safari"));
              String Info[] = (subsString.split(" ")[0]).split("/");
              browsername = Info[0];
              browserversion = Info[1];
         }         
    return browsername + "-" +browserversion;
}
%>
<% out.println(getBrowserInfo(request.getHeader("User-Agent")));%>


TOP
  
Reply with quote  
 Question subject: Re: how can we get browser information in jsp?
PostPosted: Fri Oct 14, 2011 3:33 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 57 time
thanks for add :)

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 7 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 about getting some more information  Java  Anonymous  0
 information about database  Servlets / JSP  rinasharma  0
 information about netbeans IDE  Servlets / JSP  rinasharma  1
 Send login information  PHPbb3 support  Killer  1
 Whats your favourite browser?  General Discussion  infomercialscams  15

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google Adsense [Bot] and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team