Problems and Solutions:

In the process of development, sometimes business requirements need to be processed separately for mobile terminal and PC terminal. If it is mobile terminal, page A will be returned; if it is PC terminal, page B will be returned. Both the server and the front-end JS can get the User-Agent and make the judgment, but it is shared here that the server does the processing.

Java code:
Public static Boolean isMoblieBrowser(HttpServletRequest Request) { Boolean isMoblie = false; String[] mobileAgents = { "iphone", "android", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile" }; String ua = request.getHeader("user-agent"); if (org.apache.commons.lang3.StringUtils.isNotBlank(ua)) { for (String mobileAgent : mobileAgents) { if (ua.toLowerCase().indexOf(mobileAgent) >= 0) { isMoblie = true; break; } } } return isMoblie; }Copy the code

Here, the commonly used mobile browser UA keywords are listed in an array, and then the UA of the current browser is obtained to determine whether the UA of the current browser contains one of the above array. If the element contained is found, it is the mobile browser. Test method code:

@RequestMapping("") public ModelAndView test(HttpServletRequest request) { ModelAndView mv = new ModelAndView(); System.out.println(" isMoblieBrowser: "+isMoblieBrowser(request)); if(isMoblieBrowser(request)){ mv.setViewName("mobile"); }else{ mv.setViewName("pc"); } return mv; }Copy the code

This is done by checking whether it is a mobile browser and then returning to a different page for different business processing. The original author’s technology blog: www.jianshu.com/u/ac4daaeec…

Thank you

conclusion

Checked a few data, there are several views, the server corresponding to the mobile phone and the server corresponding to the computer browser can be the same, also can not be the same, the same word is to add a processing can, and then searched this blog. The issue discussed in this blog is based on the same server, so for now it is the same server. To be solved to be supplemented, time is very tight, summary of leetcode topic