How to retain session variable
I am trying to retain the Session variable which is getting removed(deleted) in one of the Actions.
I tried passing the Session variable to another session variable and at the end, reassigned the changed variable to the original variable.
Even this does not work. After deleting the original variable, the contents of the new session variable are also getting deleted.
Can any body help me to resolve this.
How to retain the session value
Try to save the value of the session in a String variable and pass it using URL rewriting. and then retrive the value using getParameter();
first pass the Session value in the servlet context.
HttpSession sess = req.getSession(true);
ServletContext context = getServletContext();
Now in another servlet...
Object sessionIdObj = context.getAttribute("sessionId");
String sessionIdValue = sessionIdObj.toString();
Now simply use the value stored in sessionIdValue, to retain the session.