当 javascript 在其他 jsp 中第 3 次或第 4 次访问时 index.jsp returns 中设置的会话变量为 null

Session variable set in index.jsp returns null when accessed 3rd or 4th time by javascript in others jsp's

该项目正在使用 Spring 框架。

  1. 有没有办法延长会话变量超时时间?
  2. 要使整个网站都可以访问会话变量? 我不想在控制器中设置会话变量。

流程如下:

直到这里没有问题。 但是在我点击其他链接如“/test.jsp”时,"test.jsp" 中的 javascript 为

返回 null

var countryCode = '<%= session.getAttribute("countryCode") %>';

同样,如果我点击“/index.jsp”,它会将我重定向到 "country.html",因为

coun =(String) objectSession.getAttribute("countryCode");

我猜在 scriptlet 中是空的。

我使用的是 response.SendRedirect(),每次尝试都会创建一个新会话。 现在我只使用控制器而不是重定向使用 ModelAndView 来到达所需的页面。