Parsing HTTP user-agent information, using Uasparser-0.6.1.jar and Jregex-1.2_01.jar two packages
1 ImportCz.mallat.uasparser.OnlineUpdater;2 ImportCz.mallat.uasparser.UASparser;3 ImportCz.mallat.uasparser.UserAgentInfo;4 5 6 Importjava.io.IOException;7 8 /**9 * Created by Edward on 2016/7/1.Ten */ One Public classUseragentutil { A - StaticUasparser Uasparser =NULL; - the //initializing the Uasparser object - Static { - Try { -Uasparser =NewUasparser (Onlineupdater.getvendoredinputstream ()); +}Catch(IOException e) { - e.printstacktrace (); + } A } at - Public Static voidMain (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 { inUseragentinfo Useragentinfo =UserAgentUtil.uasParser.parse (str); -SYSTEM.OUT.PRINTLN ("Operating system Name:" +useragentinfo.getosfamily ());// toSYSTEM.OUT.PRINTLN ("Operating system:" +useragentinfo.getosname ());// +System.out.println ("Browser name:" +useragentinfo.getuafamily ());// -SYSTEM.OUT.PRINTLN ("browser version:" +useragentinfo.getbrowserversioninfo ());// theSYSTEM.OUT.PRINTLN ("Device type:" +Useragentinfo.getdevicetype ()); *System.out.println ("Browser:" +useragentinfo.getuaname ()); $System.out.println ("type:" +Useragentinfo.gettype ());Panax Notoginseng -}Catch(IOException e) { the e.printstacktrace (); + } A } the}
User-agent information can be viewed via the browser's own tool:
If you are using a Chrome browser
The static block in the program is executed at initialization time, and the initialization situation is as follows:
1. When a new instance of a class is created;
2. When a static method of a class is called;
3. When using a static field of a class or interface;
4. When invoking some of the reflection methods in the Java API, such as methods in class classes, or methods of classes in Java.lang.reflect;
5. When initializing a subclass;
6. When the virtual machine launches a class that is identified as the startup class (Main method);
Java Parsing HTTP user-agent information