http://blog.csdn.net/xiaoxian8023/article/details/37527133
参照上面这个大兄弟写的CheckMobile 工具类,亲测可用
过滤器代码
这样就能判断了。
参照上面这个大兄弟写的CheckMobile 工具类,亲测可用
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
System.out.println("---------------------------------------------this is a test------------------------------------------");
HttpServletRequest httpRequest = (HttpServletRequest) request;
String userAgent = httpRequest.getHeader("USER-AGENT").toLowerCase();
System.out.println("--------------------"+userAgent+"----------------------------------------");
boolean isFromMobile=CheckMobile.check(userAgent);
if(isFromMobile){
System.out.println("移动端访问");
}else {
System.out.println("pc端访问");
}
chain.doFilter(request, response);
}
过滤器代码
这样就能判断了。