
如何通過HttpServletRequest來獲取到上面的屬性呢?
1、引入開源工具
<!-- https://mvnrepository.com/artifact/eu.bitwalker/UserAgentUtils --> <dependency> <groupId>eu.bitwalker</groupId> <artifactId>UserAgentUtils</artifactId> <version>1.21</version> </dependency>
2、在controller中使用
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
Browser browser = userAgent.getBrowser();
OperatingSystem operatingSystem = userAgent.getOperatingSystem();
Version browserVersion = userAgent.getBrowserVersion();
log.info(browser.getName());
log.info(operatingSystem.getName());
log.info(browserVersion.getVersion());
3、運行結果

4、request的服務端和客戶端詳細信息
request.getLocalAddr();//獲取本地IP,即服務器IP request.getLocalName();//獲取本地名稱,即服務器名稱 request.getLocalPort();//獲取本地端口號,即Tomcat端口號 request.getLocale();//用戶的語言環境 request.getContextPath();//context路徑 request.getMethod();//GET還是POST request.getProtocol();//協議,http協議 request.getQueryString();//查詢字符串 request.getRemoteAddr();//遠程IP,即客戶端IP request.getRemotePort();//遠程端口,即客戶端端口 request.getRemoteUser();//遠程用戶 request.getRequestedSessionId();//客戶端的Session的ID request.getRequestURI();//用戶請求的URL request.getScheme();//協議頭,例如http request.getServerName();//服務器名稱 request.getServerPort();//服務器端口 request.getServletPath();//Servlet路徑
