java 判断客户端访问设备的类型 的后台方法

import java.util.regex.Matcher;

import java.util.regex.Pattern;





/**

* 验证是否是手机访问

* @param request

* @return

*/

public static boolean judgeIsPhone(HttpServletRequest request) {

boolean isPhone = false;

if (StringUtils.isNotBlank(request.getHeader("User-Agent"))) {

String userAgent = request.getHeader("User-Agent").toLowerCase();

Pattern padPattern = Pattern.compile(ipadReg, Pattern.CASE_INSENSITIVE);

Matcher padMatcher = padPattern.matcher(userAgent);

//是不是pad

if (!padMatcher.find()) {

Pattern androidPattern = Pattern.compile(androidReg, Pattern.CASE_INSENSITIVE);

Matcher androidMatcher = androidPattern.matcher(userAgent);

if (androidMatcher.find()) {

Pattern mobilePattern = Pattern.compile(mobileReg, Pattern.CASE_INSENSITIVE);

Matcher mobileMatcher = mobilePattern.matcher(userAgent);

//是否是android手机

if (mobileMatcher.find()) {

isPhone = true;

}

} else {

//是否是其它手机

Pattern pattern = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);

Matcher matcher = pattern.matcher(userAgent);

if(matcher.find()){

isPhone = true;

}

}

}

}

return isPhone;

}

 

你可能感兴趣的:(web开发,移动端开发)