File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Browser Detection with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Browser Detection with JSP" Watch "Browser Detection with JSP" New topic
Author

Browser Detection with JSP

Heitor Bembom
Greenhorn

Joined: Jul 11, 2000
Posts: 10
I am working on a project and I need to be able to detect the browser and platform on the server side so I can add it to the JSP session.
I have already tried:
System.getProperty("browser");
and
System.getProperty("browser.vendor");
THe returned value was null for both. I also tried:
request.getHeader("User-Agent");
and I got this:
on Netscape 4.7:
Mozilla/4.7 [en] (Win98; I)
and on Explorer 5.0:
Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
I can do a lot of parsing with these strings and use it for browser and platform detection but I am wondering if thre is an easier way, like the JavaScript's "navigator.appName" statement.
Thank You,
Heitor Bembom
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
The browser (JavaScript) property is identical to the one you get with the servlet's request object's method. They both interrogate the browser in the same way.
In my page http://alicea.org/detect.html you can see JavaScript in action in this respect.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Heitor Bembom
Greenhorn

Joined: Jul 11, 2000
Posts: 10
Dear Tony,
I visited your page. I am aware of how to detect browser and platform using JavaScript. I am just wondering if there is a way to do the same with Java. Another question: How can you get the screen resolution. What method do you use for that?
Thank You,
Heitor Bembom

Todd M Bush
Greenhorn

Joined: Apr 26, 2000
Posts: 22
Here is a way we are doing it. Granted, we just care if it's IE or not.
String browser = request.getHeader("User-Agent");
if(browser.indexOf("MSIE") > 0) {
// do ie stuff
}
else {
// do Netscape or other browser stuff
}
Hope it helps
Bhuvana
Greenhorn

Joined: Aug 21, 2000
Posts: 2
Hello,
Here i have given the method which accepts the value which you retrieved from getHeader("USER-AGENT") and return only the Browser type whether "NS version" or "IE version".
I think you can use this method in your program to the Browser value.
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;

}
All the Best,
Bhuvana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Browser Detection with JSP