Parsing HTTP user-agent information, using Uasparser-0.6.1.jar and Jregex-1.2_01.jar two packages
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;
Initializes 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.G Etbrowserversioninfo ());//System.out.println ("Device Type:" +useragentinfo.getdevicetype ());
System.out.println ("Browser:" +useragentinfo.getuaname ());
System.out.println ("Type:" +useragentinfo.gettype ());
catch (IOException e) {e.printstacktrace ();
}
}
}
Run Result:
User-agent information can be viewed from the browser with its own tools:
The Chrome browser is used as follows
The static block in the program, which is executed at initialization time, is initialized as follows:
1. When creating a new instance of a class;
2. When a static method of a class is invoked;
3. When using a static field of a class or interface;
4. When invoking certain 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 of the class;
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 can enjoy