国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP、判斷移動設備的正則

2019-11-02 15:05:10
字體:
來源:轉載
供稿:網友

 天貓php判斷移動設備的正則(個人猜測),覺得很好用,于是就決定移植到JSP里面,大家可以參考下

看到了一篇很好的文章, 《在天貓,前端做什么?》,里面有天貓php判斷移動設備的正則(個人猜測),覺得很好用,于是就決定移植到JSP里面。  jsp文件名為 index.jsp,其實也可以使用過濾器來進行攔截,然后跳轉到其他域名去。  完整代碼如下: 代碼如下:<[email protected] import="java.util.regex.Matcher"%> <[email protected] import="java.util.regex.Pattern"%> <%@ page language="java" pageEncoding="UTF-8"%> <%!  // b 是單詞邊界(連著的兩個(字母字符 與 非字母字符) 之間的邏輯上的間隔), // 字符串在編譯時會被轉碼一次,所以是 "b" // B 是單詞內部邏輯間隔(連著的兩個字母字符之間的邏輯上的間隔) 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 = "";&
歐美電視[www.aikan.tv/xzhtml/7/]
nbsp;} 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>  
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保康县| 全椒县| 巢湖市| 吴桥县| 木里| 来凤县| 额敏县| 许昌县| 应城市| 南召县| 高青县| 鄂托克旗| 宁陕县| 合山市| 耒阳市| 泗水县| 浦城县| 博野县| 中方县| 永宁县| 德惠市| 阳春市| 高碑店市| 紫阳县| 离岛区| 临城县| 天台县| 三门峡市| 武山县| 潢川县| 明溪县| 桐乡市| 临潭县| 茶陵县| 丰台区| 潍坊市| 贵定县| 白河县| 翁牛特旗| 柏乡县| 巍山|