我想将struts 2与spring mobile集成。在Spring官方网站上,http://docs.spring.io/spring-mobile/docs/1.1.1.RELEASE/reference/html/device.html
我已按照说明将spring mobile集成到我的项目中。在启动时,我没有遇到任何问题,但是当我尝试获取currentDevice时,我的对象为null,其中包含:
Device currentDevice = DeviceUtils.getCurrentDevice(request);
有人试图将spring mobile与struts2集成吗?
我的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>
applicationContext.xml 上我的处理程序拦截器的定义:
<bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
我的testClass:
public class AuthenticationAction extends ActionSupport implements
SessionAware, ServletRequestAware {
Log mylog = LogFactory.getLog(AuthenticationAction.class);
// So that we can lookup the current Device
private HttpServletRequest request;
@RequestMapping("/")
public String computeLogin() {
...
Device currentDevice = DeviceUtils.getCurrentDevice(request);
if (currentDevice != null) {
mylog.info("Device type: ");
mylog.info("mobile: " + currentDevice.isMobile());
mylog.info("normal " + currentDevice.isNormal());
mylog.info("tablet " + currentDevice.isTablet());
}
}
public void setSession(Map<String, Object> session) {
this.mySession = session;
}
public void setServletRequest(HttpServletRequest request) {
this.setRequest(request);
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
}