springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。

时间:2023-03-10 08:12:45
springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。

问题描述:在我写的主页面中用到了iframe,其中在iframe中有一个button点击提交,然后在Controller中返回页面的时候,是在iframe中打开的,而不是整个页面。

最开始我想用ajax来提交表单,然后用parent.location.href()来进行整个页面的跳转,但是不知道为什么,ajax请求一直返回错误,进入error页面,并且我其他的ajax没有问题,坑

最后在用这个方法解决了:

 @RequestMapping(value = "/test", method = RequestMethod.POST)
public String updateUser(HttpServletResponse response){
PrintWriter out = response.getWriter();
out.print("<script>window.parent.location.href='/account/accountIndex';</script>");
out.flush();
}
return null;
}

参考:http://blog.****.net/hellostory/article/details/7265357