jsp判断请求来自手机示例代码_JSP编程

复制代码 代码如下:

<%
String wap = "http://3g.ssss.com.cn";

String agent = request.getHeader("user-agent");
//String agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22";
String agentcheck = agent.trim().toLowerCase();
boolean isWAP = false;
String[] keywords = {"mobile", "android",
"symbianos", "iphone", "wp\\d*", "windows phone",
"mqqbrowser", "nokia", "samsung", "midp-2",
"untrusted/1.0", "windows ce", "blackberry","ucweb",
"brew", "j2me", "yulong", "coolpad", "tianyu", "ty-",
"k-touch", "haier", "dopod", "lenovo", "huaqin", "aigo-",
"ctc/1.0", "ctc/2.0", "cmcc", "daxian", "mot-",
"sonyericsson", "gionee", "htc", "zte", "huawei", "webos",
"gobrowser", "iemobile", "wap2.0","WAPI"};
Pattern pf = Pattern.compile("wp\\d*");
Matcher mf = pf.matcher(agentcheck);
if (agentcheck!=null&&(agentcheck.indexOf("windows nt") == -1 && agentcheck
.indexOf("Ubuntu") == -1)
|| (agentcheck.indexOf("windows nt") > -1 && mf.find())) {
for (int i = 0; i < keywords.length; i++) {
Pattern p = Pattern.compile(keywords[i]);
Matcher m = p.matcher(agentcheck);
//排除 苹果桌面系统 和ipad 、iPod
if (m.find() && agentcheck.indexOf("ipad") == -1
&& agentcheck.indexOf("ipod") == -1
&& agentcheck.indexOf("macintosh") == -1) {
isWAP = true;
break;
}
}
}
if (isWAP) {
response.sendRedirect(wap);
}
%>

复制代码 代码如下:

/**手机浏览器的User-Agent里的关键词*/
"Nokia",//诺基亚,有山寨机也写这个的,总还算是手机,Mozilla/5.0 (Nokia5800 XpressMusic)UC AppleWebkit(like Gecko) Safari/530
"SAMSUNG",//三星手机 SAMSUNG-GT-B7722/1.0+SHP/VPP/R5+Dolfin/1.5+Nextreaming+SMM-MMS/1.2.0+profile/MIDP-2.1+configuration/CLDC-1.1
"MIDP-2",//j2me2.0,Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1 /110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML like Gecko) Safari/413
"CLDC1.1",//M600/MIDP2.0/CLDC1.1/Screen-240X320
"SymbianOS",//塞班系统的,
"MAUI",//MTK山寨机默认ua
"UNTRUSTED/1.0",//疑似山寨机的ua,基本可以确定还是手机
"Windows CE",//Windows CE,Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)
"iPhone",//iPhone是否也转wap?不管它,先区分出来再说。Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; zh-cn) AppleWebKit/532.9 (KHTML like Gecko) Mobile/8B117
"iPad",//iPad的ua,Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; zh-cn) AppleWebKit/531.21.10 (KHTML like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10
"Android",//Android是否也转wap?Mozilla/5.0 (Linux; U; Android 2.1-update1; zh-cn; XT800 Build/TITA_M2_16.22.7) AppleWebKit/530.17 (KHTML like Gecko) Version/4.0 Mobile Safari/530.17
"BlackBerry",//BlackBerry8310/2.7.0.106-4.5.0.182
"UCWEB",//ucweb是否只给wap页面? Nokia5800 XpressMusic/UCWEB7.5.0.66/50/999
"ucweb",//小写的ucweb貌似是uc的代理服务器Mozilla/6.0 (compatible; MSIE 6.0;) Opera ucweb-squid
"BREW",//很奇怪的ua,例如:REW-Applet/0x20068888 (BREW/3.1.5.20; DeviceId: 40105; Lang: zhcn) ucweb-squid
"J2ME",//很奇怪的ua,只有J2ME四个字母
"YULONG",//宇龙手机,YULONG-CoolpadN68/10.14 IPANEL/2.0 CTC/1.0
"YuLong",//还是宇龙
"COOLPAD",//宇龙酷派YL-COOLPADS100/08.10.S100 POLARIS/2.9 CTC/1.0
"TIANYU",//天语手机TIANYU-KTOUCH/V209/MIDP2.0/CLDC1.1/Screen-240X320
"TY-",//天语,TY-F6229/701116_6215_V0230 JUPITOR/2.2 CTC/1.0
"K-Touch",//还是天语K-Touch_N2200_CMCC/TBG110022_1223_V0801 MTK/6223 Release/30.07.2008 Browser/WAP2.0
"Haier",//海尔手机,Haier-HG-M217_CMCC/3.0 Release/12.1.2007 Browser/WAP2.0
"DOPOD",//多普达手机
"Lenovo",// 联想手机,Lenovo-P650WG/S100 LMP/LML Release/2010.02.22 Profile/MIDP2.0 Configuration/CLDC1.1
"LENOVO",// 联想手机,比如:LENOVO-P780/176A
"HUAQIN",//华勤手机
"AIGO-",//爱国者居然也出过手机,AIGO-800C/2.04 TMSS-BROWSER/1.0.0 CTC/1.0
"CTC/1.0",//含义不明
"CTC/2.0",//含义不明
"CMCC",//移动定制手机,K-Touch_N2200_CMCC/TBG110022_1223_V0801 MTK/6223 Release/30.07.2008 Browser/WAP2.0
"DAXIAN",//大显手机DAXIAN X180 UP.Browser/6.2.3.2(GUI) MMP/2.0
"MOT-",//摩托罗拉,MOT-MOTOROKRE6/1.0 LinuxOS/2.4.20 Release/8.4.2006 Browser/Opera8.00 Profile/MIDP2.0 Configuration/CLDC1.1 Software/R533_G_11.10.54R
"SonyEricsson",// 索爱手机,SonyEricssonP990i/R100 Mozilla/4.0 (compatible; MSIE 6.0; Symbian OS; 405) Opera 8.65 [zh-CN]
"GIONEE",//金立手机
"HTC",//HTC手机
"ZTE",//中兴手机,ZTE-A211/P109A2V1.0.0/WAP2.0 Profile
"HUAWEI",//华为手机,
"webOS",//palm手机,Mozilla/5.0 (webOS/1.4.5; U; zh-CN) AppleWebKit/532.2 (KHTML like Gecko) Version/1.0 Safari/532.2 Pre/1.0
"GoBrowser",//3g GoBrowser.User-Agent=Nokia5230/GoBrowser/2.0.290 Safari
"IEMobile",//Windows CE手机自带浏览器,
"WAP2.0"//支持wap 2.0的
"wapi"//是中国标准 为了对抗wifi (wifi是不让用的,行货的这功能都阉割了,只有水货手机有这功能) 是无线局域网

常见智能机user agent String

Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5

MQQBrowser/25 (Linux; U; 2.3.3; zh-cn; HTC Desire S Build/GRI40;480*800)

Mozilla/5.0 (Linux; U; Android 2.3.3; zh-cn; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1 /110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413

Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8J2

Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A5313e Safari/7534.48.3

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1

Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)      ----SAMSUNG MP7

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7)         ----HTC MP7

下面是用javascript实现的 因为涉及到页面静态化为题所有要用javascript

复制代码 代码如下:

<script type="text/javascript">
function iswap(){
var agentcheck=navigator.userAgent.toLowerCase();
var chesys=true;
var isWAP=false;
var keywords = ["mobile", "android",
"symbianos", "iphone","windows phone",
"mqqbrowser", "nokia", "samsung", "midp-2",
"untrusted/1.0", "windows ce", "blackberry","ucweb",
"brew", "j2me", "yulong", "coolpad", "tianyu", "ty-",
"k-touch", "haier", "dopod", "lenovo", "huaqin", "aigo-",
"ctc/1.0", "ctc/2.0", "cmcc", "daxian", "mot-",
"sonyericsson", "gionee", "htc", "zte", "huawei", "webos",
"gobrowser", "iemobile", "wap2.0","wapi"];
//排除 windows,苹果等桌面系统 和ipad 、iPod
var rekeywords=["Windows 98", "Windows ME","Windows 2000","Windows XP","Windows NT","Ubuntu","ipad","ipod","macintosh"];

if (agentcheck!=null){
for (var i = 0; i < rekeywords.length; i++) {
if ( agentcheck.indexOf(rekeywords[i].toLowerCase())>-1){
chesys=false;
}
}
}

if (chesys){
for (var i = 0; i < keywords.length; i++) {
if ( agentcheck.indexOf(keywords[i].toLowerCase())>-1) {
isWAP = true;
break;
}
}
}
if (isWAP) {
window.location.href="http://3g.gf.com.cn";
}

}
</script>

时间: 2024-12-09 14:13:38

jsp判断请求来自手机示例代码_JSP编程的相关文章

java 判断请求来自手机或电脑

 代码如下 复制代码 package com.zhuzher.commons.util;   import javax.servlet.http.HttpServletRequest;   public class HttpRequestDeviceUtils {      /**Wap网关Via头信息中特有的描述信息*/     private static String mobileGateWayHeaders[]=new String[]{     "ZXWAP",//中兴提供的

JSP实现的简单分页显示效果代码_JSP编程

本文实例讲述了JSP实现的简单分页显示效果代码.分享给大家供大家参考,具体如下: <%@ page contentType="text/html;charset=gb2312" %> <%@ page language="java" import="java.sql.*" %> <script language="javascript"> function newwin(url) { var

jsp输出当前时间的实现代码_JSP编程

在jsp页面中输出完整的时间,格式为"年 月 日  时:分:秒" <% Date date = new Date(); SimpleDateFormat t = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = t.format(date); %> 当前时间:<%= time %> 以上就是小编为大家带来的jsp输出当前时间的实现代码全部内容了,希望大家多多支持~ 以上是小编

jsp 文件下载示例代码_JSP编程

有的时候一个模板的下载,这种简单的下载服务端已存在文件功能,就可以方便的通过jsp文件下载的方式来轻松实现.  //jsp 页面 js 复制代码 代码如下: /** * 导出角色 */ function exportRole(){ var user_id = $('input[name=userListRadio]:checked').attr('id'); if(!user_id ||user_id == ''){ showinfo('请选择用户!'); return; } var param

JSP 获取真实IP地址的代码_JSP编程

但是在通过了 Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址了.如果使用了反向代理软件,用 request.getRemoteAddr()方法获取的IP地址是:127.0.0.1或 192.168.1.110,而并不是客户端的真实IP. 经过代理以后,由于在客户端和服务之间增加了中间层,因此服务器无法直接拿到客户端的 IP,服务器端应用也无法直接通过转发请求的地址返回给客户端.但是在转发请求的HTTP头信息中,增加了X-FORWARDED-FOR信息.用以跟踪原有的客户端

纯jsp打造无限层次的树代码_JSP编程

做树并不复杂,但我们通常做的是2层或3层,那样的数据一般来自多个表,比如:部门,员工 然而这种自连接的表,其没有确定的层次,可能是无限多级 比如:a是b的上级,b是c的上级,c是d的上级... 每个上级有几个下级,下级的层次,都是动态的 解决这个问题,其实主要用到js的知识 可以使用div的innerHTML属性 当然也可以用table,用append的方法 下面就用div的innerHTML属性来实现 主要思路是通过super,在document中查找id与自身super关联的div,这个di

jsp/javascript打印九九乘法表代码_JSP编程

jsp表达式方式: 复制代码 代码如下: <center> <table border="1"> <% for (int i = 1; i <= 9; i++) { %> <tr> <% for (int j = 1; j <= 9; j++) { %> <td> <% if (j <= i) { %> <%=i%>*<%=i%>=<%=i * j%>

jsp使用cookie存储中文示例分享_JSP编程

看J2EE的时候,看见书上讲到使用cookie保存信息的时,看到书上举得例子都是英文的键值对,我就想中文是不是一样呢?试了一下果然不一样.废话不多说,直接上代码: 比如说有addCookie.jsp代码如下: 复制代码 代码如下: <html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>增加cookie</title></head><body><

jsp SmartUpload 实现上传功能代码_JSP编程

复制代码 代码如下: <%@ page contentType="text/html;charset=gb2312"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body leftmargin="0" topmargin