I don't know if you have already the sloution of your problem, but if not, here it is:
You have to cast the object, which is placed in the session scope to your desired type. The Method toString() is not the right way.
It should look like this:
String userFromSession = (String) session.getAttribute("USER1");
This could be the browser's behaviour, I faced the issue recently.
I noticed cookie settings :
Browser's settings (Firefox) :
- Keep cookies : until they expired
Tomcat's settings :
- Cookie generated by tomcat with name JSESSIONID, has attribute
"Expires : at the end of session' .
For browser, when you visit URL2 , you leave URL1 actually , and it means - "End of session for URL1" .
You can solve the problem in 2 ways :
1) set browser's setting : Keep cookies : until I close browser
2) always send to URL2 also session id to get back to URL1 .
In other words, your URL1 to return must look like