identify client machine Operating System by using request object in java web applications [duplicate]

最后都变了- 提交于 2020-01-14 05:02:40

问题


Possible Duplicate:
How can I get client infomation such as OS and browser

i want to know clients machine Operating system name when i received request in my servlet through request object

thanks in advance


回答1:


Example using the user-agent-utils library:

public class SomeServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      String userAgentString = request.getHeader("User-Agent");
      UserAgent userAgent = UserAgent.parseUserAgentString(userAgentString);
      OperatingSystem os = userAgent.getOperatingSystem();

      // Do stuff with os...
  }
}

You can read more about the OperatingSystem class here.

You can find the jar here.




回答2:


Use user-agent HTTP header. Here is how it looks like on my machine:

user-agent Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

As you can see it is a freely formatted text, so you have to investigate different user agent and process them using probably regular expression.



来源:https://stackoverflow.com/questions/13076057/identify-client-machine-operating-system-by-using-request-object-in-java-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!