jsp文件名為 index.jsp,其實(shí)也可以使用過濾器來進(jìn)行攔截,然后跳轉(zhuǎn)到其他域名去。 " /> 成人短视频app,最新日韩在线,偷拍亚洲精品

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

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

jsp文件名為 index.jsp,其實(shí)也可以使用過濾器來進(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)碼一次,所以是 "http://b"
// /B 是單詞內(nèi)部邏輯間隔(連著的兩個(gè)字母字符之間的邏輯上的間隔)
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>測試移動(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="測試,移動(dòng)設(shè)備,跳轉(zhuǎn)">
<meta http-equiv="description" content="測試移動(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>

jsp技術(shù)JSP判斷移動(dòng)設(shè)備的正則,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 温州市| 大田县| 乐业县| 盐城市| 丹阳市| 都昌县| 乐陵市| 南丹县| 五莲县| 安顺市| 化州市| 崇义县| 衡水市| 大同市| 孝昌县| 墨竹工卡县| 福安市| 白城市| 伊川县| 东兰县| 阿坝县| 新平| 常山县| 临沭县| 六安市| 江安县| 通许县| 公主岭市| 肇东市| 杭锦后旗| 赣榆县| 乳源| 浏阳市| 胶州市| 革吉县| 化隆| 峡江县| 三明市| 厦门市| 荥阳市| 天等县|