java 获取浏览器名称及版本号

java从后台获取浏览器名称及版本号,代码如下:

import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginController {
public String login(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException{
//获取浏览器信息
Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser();
//获取浏览器版本号
Version version = browser.getVersion(request.getHeader("User-Agent"));
String info = browser.getName() + "/" + version.getVersion();
return info;
}
}

备注:Browser、UserAgent、Version来自于useragentutils包中,需要在maven中引入

<dependency>
         <groupId>eu.bitwalker</groupId>
         <artifactId>UserAgentUtils</artifactId>
         <version>1.20</version>
</dependency>

即可

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭