import javax.servlet.http.HttpServletRequest;
public class HttpMobileVerify {
public static boolean isMobileDevice(HttpServletRequest request){
/**
* android : 所有android设备
* mac os : iphone ipad
* windows phone:Nokia等windows系统的手机
*/
try{
String requestHeader = request.getHeader("user-agent");
if(requestHeader == null){
return false;
}
String[] deviceArray = new String[]{"android","mac os","windows phone"};
requestHeader = requestHeader.toLowerCase();
for(int i=0;i<deviceArray.length;i++){
if(requestHeader.indexOf(deviceArray[i])>0){
return true;
}
}
}catch (Exception ex){
ex.printStackTrace();
}
return false;
}
}