Tmall PHP judged the regularity of mobile devices (personal guess) and found it very useful, so it was decided to port it to JSP, you can refer to it
I saw a very good article, "What is the front end on Tmall? 》, There is Tmall php to judge the regularity of mobile devices (personal guess), I think it is very useful, so I decided to transplant to JSP. The jsp file is named index.jsp. In fact, you can also use filters to intercept it and then jump to other domain names. The complete code is as follows: The code is as follows: <% @ page import = "java.util.regex.Matcher"%> <% @ page import = "java.util.regex.Pattern"%> <% @ page language = "java" pageEncoding = "UTF-8"%> <%! // b is the word boundary (the logical space between two consecutive (alphabetical and non-alphabetic characters)), // the string will be compiled Transcode once, so it's "b" // B is the logical interval within the word (the logical interval between two consecutive alphabetic characters) 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> Test mobile device jump </ title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "cache-control" con tent = "no-cache"> <meta http-equiv = "expires" content = "0"> <meta http-equiv = "keywords" content = "test, mobile device, jump"> <meta http-equiv = "description" content = "Test mobile jump"> <!-<link rel = "stylesheet" type = "text / css" href = "styles.css">-> </ head> <body> < div id = "pagecontent" style = "min-height: 500px; _height: 500px;"> is running! <br> </ div> </ body> </ html>