how to detect whether request is coming from browser or smartphone? [duplicate]

人盡茶涼 提交于 2019-12-14 03:28:10

问题


I am having a web application , which works fine . now there is a particular page which gets bulky when i access the application from smartphone browser , so I wanted a situation like

if(request comes from computer browser client )
forward to bulky page in web application
else
if (request comes from smartphone )
forward to some other light page .

please put your suggestion how can i achieve this


回答1:


Use the user-agent. Every connection to your server carries this header, by convenience and convention. There is no guarantee that a browser will be truthful(such as a spambot reporting itself as Chrome). You can get the user-agent as follows:

request.getHeader("User-Agent");

and then check again known user-agent strings and templates.




回答2:


It's generally done by checking "User-Agent" header of Request



来源:https://stackoverflow.com/questions/18623018/how-to-detect-whether-request-is-coming-from-browser-or-smartphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!