Total members 11895 |It is currently Sat Dec 21, 2024 6:22 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





how can we get browser information in jsp?




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

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

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


_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
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


Author:
Newbie
User avatar Posts: 1
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/>");
}
  



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

thanks for the addition .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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



Author:

thanks for add :)

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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...


Author:
Newbie
User avatar Posts: 9
Have thanks: 1 time
Post new topic Reply to topic  [ 8 posts ] 

  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 netbeans IDE     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com