0

我想将 struts 2 与 spring mobile 集成。在 Spring 官方网站上,http://docs.spring.io/spring-mobile/docs/1.1.1.RELEASE/reference/html/device.html

我已按照说明将 spring mobile 集成到我的项目中。启动时,我没有遇到任何问题,但是当我尝试获取 currentDevice 时,我的对象为空,其中:

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" />

我的测试类:

    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;
    }
}
4

0 回答 0