That will get the current HTTPSession for the client, or create one if it doesn't already exist. If the argument value to getSession() was false, no session will be created if one doesn't already exist. The following CreateSession servlet illustrates how to create a session and glean some important session statistics such as creation time, last access time, the maximum lifetime of a session in seconds and most importantly, the session id that is used to uniquely identify a client's session.
Joined: May 25, 2004
This is what i want if in the login servlet i created a session session=req.getSession(true); and set a value like session.setAttribute("WAS",strWAS)
if i want to get value in the next servlet ,then again i want to create a session or just i can use String strWAS2=session.getAttribute("WAS");
In the next servlet, if the next servlet is invoked in the same session, you would be able to just do session.getAttribute(attributeName) to get the value. You do not need to create any new session in that servlet.
But if the next servlet is not invoked in the same session, you cannot access the attribute defined in the session scope. If that is a possibility, you need to see which scope would suit you. The available scopes are -