Java Parsing HTTP user-agent information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.