5

I have a requirement where in all controllers I need to understand device type (desktop, mobile, tablet) and based on that I may need to send request to a different view. Right now, I have littered my controllers with duplicate code that does following:

  1. Get User-Agent from HttpServletRequest
  2. Find device type by matching User Agent string containing multiple pre-defined keywords in an array.
  3. Use if/else statement to forward request to different view based on detected device type

To fix this I found out that spring-mobile is able to help with this. But unfortunately it looks like this project is abandoned. I am looking for a better alternative as a dependency or maybe a better design pattern to handle this problem.

Abhinav
  • 3,322
  • 9
  • 47
  • 63
  • I am facing the same problem. Have you found any solution? – Eatsam ul haq Jun 30 '22 at 15:13
  • how do you find Device type with `HttpServletRequest`. As you have mentioned in `second step` that you matched `User-Agent containing pre-defined keywords`. What are those `Keywords`? – Eatsam ul haq Jul 13 '22 at 08:13

0 Answers0