简体   繁体   English

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

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

The project is using Spring Framework. 该项目正在使用Spring Framework。

  1. Is there a way to extend the session variable timeout ? 有没有办法延长会话变量超时时间?
  2. To make session variable accessible throughout the website ? 要使会话变量可在整个网站上访问? I don't want to set the session variables in the controller. 我不想在控制器中设置会话变量。

The flow is as follows : 流程如下:

  • '/' ie "index.jsp" calls "country.html" if session variable is set to null. 如果会话变量设置为null,则“ /”(即“ index.jsp”)将调用“ country.html”。
  • the user then selects a country in "country.html" and form is submitted to "/index.jsp" 然后用户在“ country.html”中选择一个国家,并将表单提交到“ /index.jsp”
  • Then "index.jsp" gets value using"request.getParameter(countryCode)" , if not null then it sets session variable using "objectSession.setAttribute("countryCode", IN);". 然后,“ index.jsp”使用“ request.getParameter(countryCode)”获取值,如果不为null,则使用“ objectSession.setAttribute(“ countryCode”,IN);“设置会话变量。

Uptil here there is no issue. 直到这里没有问题。 But in i click the on other links like "/test.jsp", the javascript in "test.jsp" is returning null for 但是在我单击其他链接,例如“ /test.jsp”时,“ test.jsp”中的javascript返回null

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

Similarly if i click on "/index.jsp" it is redirecting me to "country.html" because 同样,如果我单击“ /index.jsp”,它会将我重定向到“ country.html”,因为

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

in the scriptlet is null i guess. 我猜在scriptlet中为null。

I was using the response.SendRedirect() which was creating a new session on every attempt. 我正在使用response.SendRedirect(),它在每次尝试时都创建一个新会话。 Now i am using controller only but instead of redirect used ModelAndView to get to the desired page. 现在我只使用控制器,而不是使用ModelAndView重定向到所需页面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 index.html/index.jsp 上定义的 Javascript 变量用于 Vue.js? - how to make use of Javascript variable which are defined on index.html/index.jsp to Vue.js? Javascript正则表达式第一次正常运行,但第二次运行不正常,第三次而不是第四次正常工作,依此类推 - Javascript Regular Expression is working fine first time but not second time, working again for 3rd time and not for 4th and so on 我无法访问 index.jsp 中的嵌套 JavaScript function - I can't access nested JavaScript function in index.jsp 很奇怪:会话变量从post控制器返回null到jsp页面 - Weird: session variable returns null from a post controller to a jsp page 将JavaScript变量传递到JSP会话 - Pass JavaScript variable to JSP session 如何在Javascript中用空格替换第三个连字符和用冒号替换第四个连字符 - How to replace 3rd hyphen with empty space and 4th hyphen with colon in Javascript Javascript正则表达式在每第3个和第4个字符后添加破折号 - Javascript Regular Expression to add dash after every 3rd and 4th characters 如何在 JavaScript onclick 上显示不同的图像并在第 3 次或第 4 次单击时显示相同的图像 - How to show different image on JavaScript onclick and display the same image on 3rd or 4th click 如果array包含2个相同的对象,则将第二个(或第3个,第4个)对象的值突变 - If array includes 2 objects which are the same, then mutate the 2nd (or 3rd, 4th) object's values 从数组中删除 5 个元素中的第 3 个和第 4 个 - Removing every 3rd & 4th out of 5 elements from array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM