How does the Java backend determine whether the access request is mobile or PC-side?

Source: Internet
Author: User

How does the Java backend determine whether the access request is mobile or PC-side?

It is mainly based on the parameter user-agent of the request header in HttpServletRequest requests:

String useragent = Request.getheader ("user-agent");

if (Useragent.indexof ("Android")! =-1) {
Android

String Defaultfailureurl = "/login_moblie.jsp";
System.out.println ("Android Access!!! "+" no login, return page = = = "+defaultfailureurl";
......
} else if (Useragent.indexof ("IPhone")! =-1 | | useragent.indexof ("IPAD")! =-1) {
Apple

String Defaultfailureurl = "/login_moblie.jsp";
System.out.println ("Iphone/ipad Access!!! "+" no login, return page = = = "+ Defaultfailureurl);

......

} else {//Computer
String Defaultfailureurl = "/login.jsp";
SYSTEM.OUT.PRINTLN ("Computer Access!!! "+" no login, return page = = = "+ Defaultfailureurl);

...//Logical processing
}

Add your own logical handling after the judgment.

The following are the results of different access printing:

mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/57.0.2987.110 safari/537.36
Computer Access!!! No login, return to page ===/login.jsp

Android
mozilla/5.0 (Linux; Android 6.0; MZ-M5 Note build/mra58k) applewebkit/537.36 (khtml, like Gecko) version/4.0 chrome/45.0.2454.94 Mobile safari/537.36
Android Access!!! No login, return to page ===/login_moblie.jsp

Apple side
mozilla/5.0 (IPhone; CPU iPhone os 7_1_1 like Mac os X applewebkit/537.51.2 (khtml, like Gecko) version/7.0 mobile/11d201 safari/9537.53
Iphone/ipad Access!!! No login, return to page ===s/login_moblie.jsp

Android
mozilla/5.0 (Linux; Android 6.0; Dig-al00 build/huaweidig-al00; WV) applewebkit/537.36 (khtml, like Gecko) version/4.0 chrome/53.0.2785.49 Mobile mqqbrowser/6.2 tbs/043305 Safari/ 537.36 micromessenger/6.5.10.1080 Nettype/wifi LANGUAGE/ZH_CN
Android Access!!! No login, return to page ===/login_moblie.jsp




How the Java background determines whether the access request is mobile or PC-side

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.