最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JSP判斷移動(dòng)設(shè)備的正則

 更新時(shí)間:2014年03月22日 16:22:46   作者:  
天貓php判斷移動(dòng)設(shè)備的正則(個(gè)人猜測(cè)),覺(jué)得很好用,于是就決定移植到JSP里面,大家可以參考下
看到了一篇很好的文章, 《在天貓,前端做什么?》,里面有天貓php判斷移動(dòng)設(shè)備的正則(個(gè)人猜測(cè)),覺(jué)得很好用,于是就決定移植到JSP里面。

jsp文件名為 index.jsp,其實(shí)也可以使用過(guò)濾器來(lái)進(jìn)行攔截,然后跳轉(zhuǎn)到其他域名去。

完整代碼如下:
復(fù)制代碼 代碼如下:

<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%!

// \b 是單詞邊界(連著的兩個(gè)(字母字符 與 非字母字符) 之間的邏輯上的間隔),
// 字符串在編譯時(shí)會(huì)被轉(zhuǎn)碼一次,所以是 "\\b"
// \B 是單詞內(nèi)部邏輯間隔(連著的兩個(gè)字母字符之間的邏輯上的間隔)
String phoneReg = "\\b(ip(hone|od)|android|opera m(ob|in)i"
+"|windows (phone|ce)|blackberry"
+"|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp"
+"|laystation portable)|nokia|fennec|htc[-_]"
+"|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
String tableReg = "\\b(ipad|tablet|(Nexus 7)|up.browser"
+"|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);
Pattern tablePat = Pattern.compile(tableReg, Pattern.CASE_INSENSITIVE);

public boolean checkMobile(String userAgent){
if(null == userAgent){
userAgent = "";
}
// 匹配
Matcher matcherPhone = phonePat.matcher(userAgent);
Matcher matcherTable = tablePat.matcher(userAgent);
if(matcherPhone.find() || matcherTable.find()){
return true;
} else {
return false;
}
}
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//
String userAgent = request.getHeader( "USER-AGENT" ).toLowerCase();

if(null == userAgent){
userAgent = "";
}
if(checkMobile(userAgent)){
response.sendRedirect(basePath+"download.html");
//request.getRequestDispatcher("/download.html").forward(request,response);
} else {
response.sendRedirect(basePath+"index.html");
//request.getRequestDispatcher("/index.html").forward(request,response);
}
//
%>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">

<title>測(cè)試移動(dòng)設(shè)備跳轉(zhuǎn)</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="測(cè)試,移動(dòng)設(shè)備,跳轉(zhuǎn)">
<meta http-equiv="description" content="測(cè)試移動(dòng)設(shè)備跳轉(zhuǎn)">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>

<div id="pagecontent" style="min-height:500px;_height:500px;">

正在運(yùn)行!<br>
</div>

</body>
</html>

相關(guān)文章

最新評(píng)論

浮梁县| 隆林| 冕宁县| 岳阳市| 广西| 衡水市| 独山县| 安图县| 洛宁县| 河池市| 黄平县| 丹江口市| 白沙| 观塘区| 墨竹工卡县| 永济市| 孟连| 体育| 南投市| 西乌| 江孜县| 志丹县| 长寿区| 德格县| 云南省| 保靖县| 东海县| 深水埗区| 嘉义市| 长寿区| 光泽县| 崇文区| 西宁市| 清远市| 信丰县| 体育| 中江县| 台安县| 太保市| 巩义市| 合作市|