See a very good article, "in the sky Cat, what is the front end?" ", there are days in the cat PHP to determine the mobile device (personal guess), feel very good, so decided to migrate to the JSP inside.
The JSP file name is index.jsp, actually also can use the filter to intercept, then jumps to other domain names to go.
The complete code is as follows:
Copy Code code as follows:
<% @page import= "Java.util.regex.Matcher"%>
<% @page import= "Java.util.regex.Pattern"%>
<%@ page language= "java" pageencoding= "UTF-8"%>
<%!
\b is a logical interval between a word boundary (a string of two letters and non-alphanumeric characters),
The string is coded once at compile time, so it is "\\b"
\b is the logical interval between the internal logical intervals of a word (two alphabetic characters attached).
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 = "";
}
The
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>
<base href= "<%=basePath%>" >
<title> Test mobile device Jump </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= "test, mobile device, jump" >
<meta http-equiv= "description" content= "Test mobile device Jump" >
<!--
<link rel= "stylesheet" type= "Text/css" href= "Styles.css" >
-->
<body>
<div id= "PageContent" style= "min-height:500px;_height:500px;" >
It's running! <br>
</div>
</body>