博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 通过request.getHeader("user-agent")解析浏览器
阅读量:5845 次
发布时间:2019-06-18

本文共 3421 字,大约阅读时间需要 11 分钟。

hot3.png

/** *  * @author cc * 20120307 */public class BrowseTool {	private final static String IE9="MSIE 9.0";	private final static String IE8="MSIE 8.0";	private final static String IE7="MSIE 7.0";	private final static String IE6="MSIE 6.0";	private final static String MAXTHON="Maxthon";	private final static String QQ="QQBrowser";	private final static String GREEN="GreenBrowser";	private final static String SE360="360SE";	private final static String FIREFOX="Firefox";	private final static String OPERA="Opera";	private final static String CHROME="Chrome";	private final static String SAFARI="Safari";	private final static String OTHER="其它";			public String checkBrowse(String userAgent){		if(regex(OPERA, userAgent))return OPERA;		if(regex(CHROME, userAgent))return CHROME;		if(regex(FIREFOX, userAgent))return FIREFOX;		if(regex(SAFARI, userAgent))return SAFARI;		if(regex(SE360, userAgent))return SE360;		if(regex(GREEN,userAgent))return GREEN;		if(regex(QQ,userAgent))return QQ;		if(regex(MAXTHON, userAgent))return MAXTHON;		if(regex(IE9,userAgent))return IE9;		if(regex(IE8,userAgent))return IE8;		if(regex(IE7,userAgent))return IE7;		if(regex(IE6,userAgent))return IE6;		return OTHER;	}	public boolean regex(String regex,String str){		Pattern p =Pattern.compile(regex,Pattern.MULTILINE);		Matcher m=p.matcher(str);		return m.find();	}		public static void main(String[] args) {		String ie9    ="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";		String ie8    ="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322)";		String ie7    ="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322)";		String ie6    ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)";		String aoyou  ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Maxthon 2.0)";		String qq     ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322) QQBrowser/6.8.10793.201";		String green  ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; GreenBrowser)";		String se360  ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; 360SE)";				String chrome ="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Chrome/9.0.570.0 Safari/534.11";               		String safari ="Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8";		String fireFox="Mozilla/5.0 (Windows NT 5.2; rv:7.0.1) Gecko/20100101 Firefox/7.0.1";		String opera  ="Opera/9.80  (Windows NT 5.2; U; zh-cn) Presto/2.9.168 Version/11.51";		String other  ="(Windows NT 5.2; U; zh-cn) Presto/2.9.168 Version/11.51";		BrowseTool b=new BrowseTool();		System.out.println(b.checkBrowse(ie9));		System.out.println(b.checkBrowse(ie8));		System.out.println(b.checkBrowse(ie7));		System.out.println(b.checkBrowse(ie6));		System.out.println(b.checkBrowse(aoyou));		System.out.println(b.checkBrowse(qq));		System.out.println(b.checkBrowse(green));		System.out.println(b.checkBrowse(se360));		System.out.println(b.checkBrowse(chrome));		System.out.println(b.checkBrowse(safari));		System.out.println(b.checkBrowse(fireFox));		System.out.println(b.checkBrowse(opera));		System.out.println(b.checkBrowse(other));	}	}

引用页面:http://www.oschina.net/code/snippet_114195_9146

转载于:https://my.oschina.net/u/3647620/blog/1552464

你可能感兴趣的文章
一步步学习EF Core(3.EF Core2.0路线图)
查看>>
网络ASI
查看>>
Luogu P4707 重返现世
查看>>
目标与绩效管理实战专家胡立
查看>>
axios 中断请求
查看>>
2014手机分析图
查看>>
Linux PID 1 和 Systemd
查看>>
一元多项式相加
查看>>
commandLink/commandButton/ajax backing bean action/listener method not invoked (转)
查看>>
软件工作的大环境
查看>>
梅沙教育APP简单分析-版本:iOS v1.2.21-Nathaneko-佳钦
查看>>
Word中如何设置图片与段落的间距为半行
查看>>
JQuery this和$(this)的区别及获取$(this)子元素对象的方法
查看>>
关于分区索引与全局索引性能比较的示例
查看>>
C语言之指针与数组总结
查看>>
沟通:用故事产生共鸣
查看>>
1080*1920 下看网站很爽
查看>>
Android类参考---Fragment(一)
查看>>
CMake 构建项目Android NDK项目基础知识
查看>>
算法 - 最好、最坏、平均复杂度
查看>>