Introduction In this post, I will explain how to switch view based on devices on the web application - like pc, smartphone, tablet. The basic strategy is checking user agenet which is sent from these devices, and building the specific html for the device. The key issue uis how to check user agent of all coming http requests efficiently and ellegantly. If you use some web application framework such as Java Spring Framework or PHP Symfony framework, the solution is using &qout;Filter&qout; which every http requests pass through. Let me show you the example implementation using Spring framework. Basic Strategy In filter check if "view_mode" in user cookies, set the view mode based on that cookie value if the cookie does not exist, set view mode based on user agent and publish corresponding view mode cookie set the selected view mode to HttpServletRequest attribute. In controller, set view template based on view mode in the HttpServletRequest attribute ...
IT関連の技術やプログラミングを中心に記事を書いています。ハードウェアも好きなので、日々のちょっとしたお役立ち情報も投稿しています。