jsp文件名為 index.jsp,其實也可以使用過濾器來進行攔截,然后跳轉到其他域名去。 " /> 添望write.as女装,热99re久久精品天堂vr,一级毛片在线

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

JSP判斷移動設備的正則

看到了一篇很好的文章, 《在天貓,前端做什么?》,里面有天貓php判斷移動設備的正則(個人猜測),覺得很好用,于是就決定移植到JSP里面。

jsp文件名為 index.jsp,其實也可以使用過濾器來進行攔截,然后跳轉到其他域名去。

完整代碼如下:
復制代碼 代碼如下:
<%@page import="Java.util.regex.Matcher"%>
<%@page import="Java.util.regex.Pattern"%>
<%@ page language="Java" pageEncoding="UTF-8"%>
<%!

// /b 是單詞邊界(連著的兩個(字母字符 與 非字母字符) 之間的邏輯上的間隔),
// 字符串在編譯時會被轉碼一次,所以是 "http://b"
// /B 是單詞內部邏輯間隔(連著的兩個字母字符之間的邏輯上的間隔)
String phoneReg = "http://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 = "http://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>測試移動設備跳轉</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="測試,移動設備,跳轉">
<meta http-equiv="description" content="測試移動設備跳轉">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>

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

正在運行!<br>
</div>

</body>
</html>

jsp技術JSP判斷移動設備的正則,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 欧美极品欧美精品欧美图片 | 五月婷婷深爱五月 | 午夜精品久视频在线观看 | 精品无人区一区二区三区 | 国产精品 第二页 | 成人精品视频在线观看播放 | 国产3区 | 好吊操在线观看 | 一区二区三区网站在线免费线观看 | 玖玖精品在线视频 | 97碰视频人人做人人爱欧美 | 伊人色综合久久成人 | 国产精品福利午夜一级毛片 | 亚洲免费小视频 | 亚洲综合日韩欧美一区二区三 | 免费一区二区三区视频导航 | 91在线观| 四虎精品视频在线永久免费观看 | 久久青草免费97线频观 | 青草社区视频 | 国语自产免费精品视频在 | 青青视频国产在线播放 | 国产热re99久久6国产精品 | 久久久中文字幕 | 色多多在线| 国产一区在线视频 | h视频免费观看 | 久久九九免费视频 | 日韩精品国产自在久久现线拍 | 亚洲国产91| 精品久久久久久久久久久久久久久 | 国产91精品露脸国语对白 | 精品久久久中文字幕 | 亚洲视频一区二区三区四区 | 婷婷六月激情在线综合激情 | 欧美高清狂热视频60一70 | 天天天干| 国内精品亚洲 | 一区二区三区四区五区 | 欧美成人三级网站在线观看 | 九九九精品在线观看 |