0

I need to write two separate view section for users; one for those who access the website using iPad and those accessing otherwise.

I know it is possible in JavaScript, but I need to identify the device using Java.

I am using struts2 and hibernate in my project.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user359187
  • 2,269
  • 6
  • 29
  • 44
  • 1
    `request.getHeader("User-Agent")` –  Apr 19 '12 at 08:44
  • You are better off looking to CSS for this type of functionality. E.G. see [this thread](http://stackoverflow.com/q/6370690/418556). The `User-Agent` string is not only notoriously unreliable, but once you've figured the typical string for an iPad, you realize that only covers ..40%(?) of your tablet users, who might otherwise be using an Android or Linux (or..) based tablet. – Andrew Thompson Apr 19 '12 at 08:53

1 Answers1

2

You can read the "User-Agent" header the client sends.

Johni
  • 2,933
  • 4
  • 28
  • 47
  • When i detect user-agent and it get a long string like "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0 ", if it is mozilla and is crome another long message like "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19" and if ipad another long message etc, from this how can i identify which is i am using to access the website? – user359187 Apr 20 '12 at 06:47
  • That would be another question. Regular expressions come to mind. – Quaternion Apr 23 '12 at 08:26