We have the requirement of going to Vendor login page from the main application. If the session is valid then the data selected in the main application is visible in the Vendor page are we are storing the data in session. For Handling this, in Tomcat we had below code in the starting of Vendor login jsp.
request.getSession().invalidate();
We are migrating now to Websphere Application Server. The same code is not working in WAS. We are getting IllegalStateException. Somewhere I read that WAS handles session through cookies. So IllegalStateException is thrown if session is already invalidated.
I changed the code to as below for WAS: userId is the user id which I am saving in session in the main application.
if ((request.getSession() != null) && (request.getSession().getAttribute("userId") != null)) { // Old session
request.getSession().invalidate();
}
Even if control is going inside the if condition, it is giving IllegalStateException. For our requirement I have one alternative to remove all session parameters in the starting of vendor login jsp, so that nothing is passed. But for that I have to remove each parameter (almost 20 are there) one by one. And also in future any new parameter I will save in session, I have to update this jsp.
Is there any solution to invalidate the entire session first if it's old?