想象下面两行伪代码:

1. setCookie(...);
2. redirect(new_web_url);

首先设置一个Cookie,然后重定向到另外一个网址,这个网址跟当前网站的域名不同

在多数情况下这两行代码执行毫无问题,cookie 正确保存到浏览器,页面也跳转到了新的url上。

但是有很多firefox浏览器下可能出现的问题是cookie无法写入,而 url 跳转成功。还不一定能重现出来这种问题,但发生的概率非常高。

解决的办法:

不要直接 redirect 到另外的网址,而改用:

1
2
3
String new_url = "http://www.oschina.net/";
String html = "<script type='text/javascript'>location.href='"+new_url+"';</script>";
response.getWriter().print(html);

如此 cookie 就可以保证正确写到浏览器,然后执行页面跳转。

相关文章:

  • 2022-12-23
  • 2021-09-26
  • 2022-01-29
  • 2021-10-12
  • 2022-01-22
  • 2022-12-23
  • 2021-12-05
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2021-04-05
  • 2021-07-28
  • 2022-12-23
相关资源
相似解决方案