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:
- Get User-Agent from HttpServletRequest
- Find device type by matching User Agent string containing multiple pre-defined keywords in an array.
- 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.
HttpServletRequest
. As you have mentioned insecond step
that you matchedUser-Agent containing pre-defined keywords
. What are thoseKeywords
? – Vagrant