因了需要用到这些信息,所以总结一下,方便以后参阅
通过request.getHeader("User-Agent")大致可以取得用户浏览器的信息
如果里面包含:
"msie"-->MicroSoft
"opera" -->Opera Software
"mozilla"-->Netscape Communications
如果取浏览器版本信息
String str = request.getHeader("User-Agent");
MS : str.substring(str.indexOf("msie") + 5);
Other :
tmpString = (str.substring(tmpPos = (str.indexOf("/")) + 1, tmpPos + str.indexOf(" "))).trim(); //没有亲自试
操作系统部分,不啰嗦了
private void setOs()
{
if (this.userAgent.indexOf("win") > -1){
if (this.userAgent.indexOf("windows 95") > -1 || this.userAgent.indexOf("win95") > -1){
this.os = "Windows 95";
}
if (this.userAgent.indexOf("windows 98") > -1 || this.userAgent.indexOf("win98") > -1){
this.os = "Windows 98";
}
if (this.userAgent.indexOf("windows nt") > -1 || this.userAgent.indexOf("winnt") > -1){
this.os = "Windows NT";
}
if (this.userAgent.indexOf("win16") > -1 || this.userAgent.indexOf("windows 3.") > -1){
this.os = "Windows 3.x";
}
}
}
获取语言request.getHeader("Accept-Language");
详细信息可以再分解....