Switch to full style
What's behind JSP & Servlets
Post a reply

how can we get browser information in jsp?

Wed Oct 22, 2008 2:04 am

how can we get browser information in jsp?



Re: how can we get browser information in jsp?

Wed Oct 22, 2008 2:04 am

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

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


Re: how can we get browser information in jsp?

Fri Oct 23, 2009 5:25 am

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;

}


Re: how can we get browser information in jsp?

Mon Nov 02, 2009 1:57 pm

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/>");
}
  


Re: how can we get browser information in jsp?

Mon Nov 02, 2009 3:15 pm

thanks for the addition .

Re: how can we get browser information in jsp?

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")));%>


Re: how can we get browser information in jsp?

Fri Oct 14, 2011 3:33 pm

thanks for add :)

Re: how can we get browser information in jsp?

Sat Jan 12, 2013 6:32 am

For the browser part you need to parse the reqeust's User-Agent section.
String browserType = request.getHeader("User-Agent");
There you'll find the relevant information...

Post a reply
  Related Posts  to : how can we get browser information in jsp?
 $.browser Check if your browser is IE or FireFox or Chrome     -  
 Browser     -  
 Browser Support     -  
 Whats your favourite browser?     -  
 AJAX - Browser support     -  
 Video Archive Browser in java     -  
 Java Web Browser (Mini Project)     -  
 Browser Celsius to Fahrenheit Converstion applet     -  
 Get the client navigator browser type or operating system     -  
 information about database     -