将我的spring应用程序重定向到移动设备上的不同域时出错



我正在开发一个在移动和web上运行的Spring应用程序。在网络上,一切都运行良好,但在手机上,当表单发布时,它会击中控制器,控制器会重定向到其他应用程序。

@RequestMapping(value = "/common", method = RequestMethod.GET)
public String showLandingPage(HttpServletRequest req, HttpServletResponse response, Model model) {
logger.debug("Received request to set partner info");
Device currentDevice                = DeviceUtils.getCurrentDevice(req);
setCookies(response);
Properties props = new Properties();
try {
    props.load(getClass().getClassLoader().getResourceAsStream( "sampleApp.properties"));
} catch (IOException e) {
    logger.fatal(new StringBuilder("MainController : setCookies() : Error while reading sampleApp.properties "+e));
}catch (Exception e) {
    logger.fatal(new StringBuilder("MainController : setCookies() : Error while reading sampleApp.properties "+e));
}
if(currentDevice.isMobile() || currentDevice.isTablet()){
    return "redirect:"+props.getProperty("popcorn-mobile-url");
} else {               
    return "redirect:"+props.getProperty("popcorn-web-url");
}
}

当控件转到重定向位置时,我会在屏幕上看到"错误加载页面"。

在JSP中,我使用以下jQuery库。

    <script src="${pageContext.request.contextPath}/js/mobile/mobile-config.js"></script> 
    <script src="${pageContext.request.contextPath}/js/mobile/jquery.mobile-1.2.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/mobile/plugins.js"></script>

我需要一个设备拦截器,如下所示:

public class DeviceInterceptor extends HandlerInterceptorAdapter {    
private final DeviceResolver deviceResolver;
    private Device device;
    /**
     * Create a device resolving {@link HandlerInterceptor} that defaults to a
     * {@link LiteDeviceResolver} implementation.
     */
    public DeviceInterceptor() {
        this(new LiteDeviceResolver());
    }
    public DeviceInterceptor(DeviceResolver deviceResolver) {
        this.deviceResolver = deviceResolver;
    }
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler) throws Exception    {
        device = deviceResolver.resolveDevice(request);
        request.setAttribute(DeviceUtils.CURRENT_DEVICE_ATTRIBUTE, device);
        return true;
    }
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler, ModelAndView modelAndView) throws Exception {
    if (device.isMobile()) {
            modelAndView.setViewName("/mobile/" + modelAndView.getViewName());
        }else {
            modelAndView.setViewName("/jsp/" + modelAndView.getViewName());
        }           
    }

相关内容

  • 没有找到相关文章

最新更新