上下文:(Java)Web应用程序使用apache shiro进行会话管理,身份验证和授权。现在,仅对于移动用户而言,会话属性需要在创建过程中进行更改(例如:增加会话超时间隔等)。
如何区分移动客户端和桌面浏览器客户端?浏览器用户代理可能会提供该值,但是它可靠吗?
当移动设备使用Web应用程序时,还需要注意哪些其他事项(就后端的会话处理而言)?
我们发现使用spring移动设备模块最简单:http://docs.spring.io/spring-mobile/docs/current/reference/html/device.html
您只需将servlet过滤器添加到web.xml中,它将在请求中保留当前设备信息:
<filter>
<filter-name>deviceResolverRequestFilter</filter-name>
<filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>deviceResolverRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
然后您可以使用实用程序获取信息
Device currentDevice = DeviceUtils.getCurrentDevice((HttpServletRequest) request);
if (currentDevice != null && (currentDevice.isMobile() || currentDevice.isTablet())){
//do mobile stuff
} else {
//do desktop stuff
}
该库处理所有用于检测移动设备的用户代理程序。
至于第二个问题,如果网页是从移动设备或台式机加载的,则在服务方面并没有什么区别。他们都有HttpSessions,Cookie等。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句