根据当前请求的特征,判断该请求是否来自手机终端,主要检测特殊的头信息,以及user-Agent这个header
public static boolean isMobileDevice(HttpServletRequest request){
boolean b = false; boolean pcFlag = false; boolean mobileFlag = false; String via = request.getHeader("Via"); String userAgent = request.getHeader("user-agent"); for (int i = 0; via!=null && !via.trim().equals("") && i < mobileGateWayHeaders.length; i++) { if(via.contains(mobileGateWayHeaders[i])){ mobileFlag = true; break; } } for (int i = 0;!mobileFlag && userAgent!=null && !userAgent.trim().equals("") && i < mobileUserAgents.length; i++) { if(userAgent.contains(mobileUserAgents[i])){ mobileFlag = true; break; } } for (int i = 0; userAgent!=null && !userAgent.trim().equals("") && i < pcHeaders.length; i++) { if(userAgent.contains(pcHeaders[i])){ pcFlag = true; break; } } if(mobileFlag==true && pcFlag==false){ b=true; } return b;//false pc true shouji }