1.在Spring MVC当使用RedirectView或者"redirect:"前缀来做重定向时,Spring MVC最后会调用:
response.sendRedirect(response.encodeRedirectURL(url));
2.对于浏览器来说,打开一个新的浏览器窗口,第一次访问服务器时,encodeRedirectURL()会在url后面附加上一段jsessionid,如果初始的url为"http://www.sina.com.cn",最终得到的url为"http://www.sina.com.cn;jsessionid=2jcligmgi6fh"。
3.这种带有分号的链接,会导致出现一下错误
The request was rejected because the URL contained a potentially malicious String ";"报错解决
4.这是典型的Java做事的方式,其他语言的服务器端平台并不会这样做
5.三种解决方法.我使用了第一种,是可以解决的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 解决方法: 1. 不通过Spring MVC做重定向,自己直接调用: response.sendRedirect(url); return null; //告诉Spring MVC我已经完成了处理 2. 修改Spring MVC的代码,将: response.sendRedirect(response.encodeRedirectURL(url)); 改为: response.sendRedirect(url); 3. encodeRedirectURL()仅在无法确定浏览器是否支持cookie的时候才会在url后面附加上jsessionid,如果它能找到一个jsessionid的cookie,它就认为浏览器是支持cookie的。因此可以自己创建一个jsessionid的cookie来欺骗encodeRedirectURL()。 Cookie cookie = new Cookie("jsessionid", "2jcligmgi6fh"); cookie.setMaxAge(Integer.MAX_VALUE); response.addCookie(cookie); 然后再调用Spring MVC的重定向功能就没有问题了: return new ModelAndView("redirect:"+url); |