簡體   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

該項目正在使用Spring Framework。

  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 ='<%= session.getAttribute(“ countryCode”)%>';;

同樣,如果我單擊“ /index.jsp”,它會將我重定向到“ country.html”,因為

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

我猜在scriptlet中為null。

我正在使用response.SendRedirect(),它在每次嘗試時都創建一個新會話。 現在我只使用控制器,而不是使用ModelAndView重定向到所需頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM