2

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

Community
  • 1
  • 1
Clarence
  • 33
  • 1
  • 4

2 Answers2

4

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.

misterManSam
  • 24,303
  • 11
  • 69
  • 89
uldall
  • 2,458
  • 1
  • 17
  • 31
0

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.

AlexR
  • 114,158
  • 16
  • 130
  • 208