【开发工具】判断请求源是 手机 or PC

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;i0){
                    return true;
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return false;
    }
}

 

你可能感兴趣的:(program)