当 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 框架。
- 有没有办法延长会话变量超时时间?
- 要使整个网站都可以访问会话变量?
我不想在控制器中设置会话变量。
流程如下:
- '/' 即如果会话变量设置为空,"index.jsp" 调用 "country.html"。
- 用户然后在 "country.html" 中选择一个国家并将表单提交到“/index.jsp”
- 然后 "index.jsp" 使用 "request.getParameter(countryCode)" 获取值,如果不为空则使用 "objectSession.setAttribute("countryCode", IN);.
设置会话变量
直到这里没有问题。
但是在我点击其他链接如“/test.jsp”时,"test.jsp" 中的 javascript 为
返回 null
var countryCode = '<%= session.getAttribute("countryCode") %>';
同样,如果我点击“/index.jsp”,它会将我重定向到 "country.html",因为
coun =(String) objectSession.getAttribute("countryCode");
我猜在 scriptlet 中是空的。
我使用的是 response.SendRedirect(),每次尝试都会创建一个新会话。
现在我只使用控制器而不是重定向使用 ModelAndView 来到达所需的页面。
该项目正在使用 Spring 框架。
- 有没有办法延长会话变量超时时间?
- 要使整个网站都可以访问会话变量? 我不想在控制器中设置会话变量。
流程如下:
- '/' 即如果会话变量设置为空,"index.jsp" 调用 "country.html"。
- 用户然后在 "country.html" 中选择一个国家并将表单提交到“/index.jsp”
- 然后 "index.jsp" 使用 "request.getParameter(countryCode)" 获取值,如果不为空则使用 "objectSession.setAttribute("countryCode", IN);. 设置会话变量
直到这里没有问题。 但是在我点击其他链接如“/test.jsp”时,"test.jsp" 中的 javascript 为
返回 nullvar countryCode = '<%= session.getAttribute("countryCode") %>';
同样,如果我点击“/index.jsp”,它会将我重定向到 "country.html",因为
coun =(String) objectSession.getAttribute("countryCode");
我猜在 scriptlet 中是空的。
我使用的是 response.SendRedirect(),每次尝试都会创建一个新会话。 现在我只使用控制器而不是重定向使用 ModelAndView 来到达所需的页面。