How to update session attribute
To access the abc
variable in the JSP try:
${sessionScope.abc}
Also note that removing before setting is usually redundant. So:
request.getSession().removeAttribute("abc");
request.getSession().setAttribute("abc", abc);
Can simply become:
request.getSession().setAttribute("abc", abc);
Vaishali
Updated on July 09, 2022Comments
-
Vaishali almost 2 years
I have some session attributes being saved. I have a jsp page on which a call to a servlet is made through. This servlet updates one of the session variable but I am not able to see the reflection of these changes in my jsp.Pls help.
In My servlet
List<DriverList> abc = dao.getABC(); request.getSession().removeAttribute("abc"); request.getSession().setAttribute("abc", abc);
In my jsp
function update() { var url = "updateServlet"; var req = $.ajax({ type: 'GET', url: url, cache: false, type: "GET", success: function() { latlng = []; latlng = [<c:forEach var="test" items="${abc}"> [<c:out value="${test.latitude}"/>,<c:out value="${test.longitude}"/>,"<c:out value= "${test.name}" />",<c:out value="${test.cellNo}"/>], </c:forEach> ]; }, error: function (status) { } }); }
The value of
${abc}
is same as before. How to get the new value ?The exact flow -
when login servlet is called
abc
value assessionAttribute
is set.Now this redirects to base.jsp. I use abc for the first time. Now after every 30 seconds this
update()
function is called. This update function calls a servlet through ajax where the session attribute abc is updated.In the success function of ajax request I want to use this new abc value but getting the old one again.