Analyze http user-agent information, using two packages: uasparser-0.6.1.jar and jregex-1.2_01.jar
import cz.mallat.uasparser.OnlineUpdater;import cz.mallat.uasparser.UASparser;import cz.mallat.uasparser.UserAgentInfo;import java.io.IOException;/** * Created by Edward on 2016/7/1. */public class UserAgentUtil { static UASparser uasParser = null; // Initialize the uasParser object static { try { uasParser = new UASparser(OnlineUpdater.getVendoredInputStream()); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { String str = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"; System.out.println(str); try { UserAgentInfo userAgentInfo = UserAgentUtil.uasParser.parse(str); System.out.println("Operating system name: "+userAgentInfo.getOsFamily());// System.out.println("Operating system: "+userAgentInfo.getOsName());// System.out.println("Browser name: "+userAgentInfo.getUaFamily());// System.out.println("Browser version: "+userAgentInfo.getBrowserVersionInfo());// System.out.println("DeviceType()); System.out.println("Browser:"+userAgentInfo.getUaName()); System.out.println("Type:"+userAgentInfo.getType()); } catch (IOException e) { e.printStackTrace(); } }} Running results:
User-Agent information can be viewed through the browser's own tools:
The following is the Chrome browser
The static block in the program is executed during initialization. The initialization situation is as follows:
1.When creating a new instance of a certain class;
2. When calling a static method of a certain class;
3. When using static fields of a certain class or interface;
4. When calling certain reflection methods in the Java API, such as methods in class Class, or methods of classes in java.lang.reflect;
5. When initializing a subclass;
6. When the virtual machine starts a class marked as the startup class (main method);
The above is the entire content of this article. I hope you like it