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