jsp文件名為 index.jsp,其實也可以使用過濾器來進行攔截,然后跳轉到其他域名去。 " /> 综合色99,91美女网站,近亲伦l中文字幕

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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判斷移動設備的正則,轉載需保留來源!

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

主站蜘蛛池模板: 金针菇尽量少吃最好不吃什么| 让我们的家更美好教学设计| 尤克里里指弹谱| 沉默的羔羊1| 朱莉娅·奥蒙德| 勇者1—42集免费观看电视剧视频| 天地争霸美猴王免费观看完整版| 简单的应急预案怎么写| 吴京的《战狼3》| 郑艳丽三级| 秃探与俏妞| 玫瑰的故事剧照| 掐脖子自制短视频| 凶宅幽灵| 预备党员思想汇报1500字| 妹妹扮演的角色| 黄色网址视频免费| 国考岗位| 美丽分贝 电视剧| 年轻阿姨的性教育| dj舞曲超劲爆dj| 抖音下载安装i| 齐力电影| 二年级上册期末真题卷| 火与剑| 小姐诱心在线观看| 炊事班的故事演员表| 茶馆剧本完整版| 香港毛片免费看| 奇爱博士| 人口高质量发展论文800字| 美女的逼逼视频| 戮神| 地铁电影| 赵艳红| 诈欺游戏电影| 五年级下册语文第六单元作文450字| 色在线播放| 周韦彤写真| 我们的高清免费视频观看| 珀利|