Infer the client phone type and jump to the corresponding app download page

Source: Internet
Author: User

The principle of implementation is to detect the user-agent of the browser and then determine the client type based on the regular form.

assumptions do not match, fallback fallback policy is to display the corresponding page. Let the user choose for themselves.
suitable for the use of two-dimensional code scanning mode to download the app:

the code for the JSP version number, such as the following see: Other server version number please Baidu search.

Original address: [You can also visit the Upward Exchange forum to see many other industries, open source, recruitment information]

<% @page import= "Java.util.regex.Matcher"%><% @page import= "java.util.regex.Pattern"%><%@ page Language= "java" pageencoding= "UTF-8"%><%!//\b is the word boundary (a logical interval between two (alphabetic and non-alphabetic characters), and the string is transcoded at compile time, so it is "\\b"//\b is the internal logical interval of the word (the logical interval between the two alphabetic characters that are 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);p ublic 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.iyhjy.com/ 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 ">



Infer the client phone type and jump to the corresponding app download page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.