Determine the type of client phone and jump to the corresponding app download page
The principle of implementation is to detect the header of the browser's user-agent, and then to determine the client type based on the regular expression.
If they do not match, the fallback fallback strategy is to display the corresponding page, let the user choose for themselves.
Suitable to use two-dimensional code scanning way to download the app:
The code for the JSP version looks like this: Other service-side versions please Baidu search.
<% @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 the words (two alphabetic characters attached) string Androidreg = "\\bandroid|
nexus\\b ";
String iosreg = "IP (hone|od|ad)";
Pattern Androidpat = Pattern.compile (Androidreg, pattern.case_insensitive);
Pattern Iospat = Pattern.compile (Iosreg, pattern.case_insensitive);
public boolean likeandroid (String useragent) {if (null = = useragent) {useragent = "";
}///match Matcher matcherandroid = Androidpat.matcher (useragent);
if (Matcherandroid.find ()) {return true;
else {return false;
} public boolean Likeios (String useragent) {if (null = = useragent) {useragent = "";
}///match Matcher Matcherios = Iospat.matcher (useragent);
if (Matcherios.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 ();
System.out.println ("useragent:" +useragent);
if (null = = useragent) {useragent = "";}
if (Likeandroid (useragent)) {System.out.println ("likeandroid:" +true);
Response.sendredirect ("http://m.jb51.net/download.jsp?platform=android");
Return
Request.getrequestdispatcher ("/download.html"). Forward (Request,response);
else if (Likeios (useragent)) {System.out.println ("Likeios:" +true);
Response.sendredirect ("http://itunes.apple.com/us/app/id714751061");
Return
Request.getrequestdispatcher ("/index.html"). Forward (Request,response); }%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">