Jquery mobile 将我的spring应用程序重定向到手机上的不同域时出错
我正在开发一个运行在移动和web上的Spring应用程序。在web上,一切都可以正常运行,但在移动设备上,当表单发布时,它会命中控制器,控制器会重定向到其他应用程序Jquery mobile 将我的spring应用程序重定向到手机上的不同域时出错,jquery-mobile,spring-mvc,cross-domain,Jquery Mobile,Spring Mvc,Cross Domain,我正在开发一个运行在移动和web上的Spring应用程序。在web上,一切都可以正常运行,但在移动设备上,当表单发布时,它会命中控制器,控制器会重定向到其他应用程序 @RequestMapping(value = "/common", method = RequestMethod.GET) public String showLandingPage(HttpServletRequest req, HttpServletResponse response, Model model) { logge
@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());
}
}
嗨,谢谢你的回答。。就连我也在做同样的事。。如果是移动设备,我将调用仅为移动设备定制的页面。。但是我遇到了问题,因为我重定向到的位置位于不同的域中。。因此,我从jquery.mobile-1.2.0.js中得到了“错误加载页面”。拦截器意味着你有一个单一的责任点,而不是在每个控制器中定义它。你得到的确切信息是什么?如果页面不在那里,那么它将无法工作。