代码之家  ›  专栏  ›  技术社区  ›  Savio menezes

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

  •  0
  • Savio menezes  · 技术社区  · 7 年前

    该项目使用Spring框架。

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

    • 如果会话变量设置为null,“/”即“index.jsp”调用“country.html”。
    • 然后,用户在“country.html”中选择一个国家,并将表单提交到“/index.jsp”
    • 然后“index.jsp”使用“request.getParameter(countryCode)”获取值,如果不为null,则使用“objectSession.setAttribute(“countryCode”,IN);”设置会话变量。

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

    var countryCode='<%=一场getAttribute(“countryCode”)%>

    类似地,如果我点击“/index.jsp”,它会将我重定向到“country.html”,因为

    CONU=(字符串)objectSession。getAttribute(“countryCode”);

    我想在scriptlet中是空的。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Savio menezes    7 年前

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