First you need to get the Session object from the request.
This is an HTTPServletRequest object sent to the servlet (you will have access to this in the doGet or doPost method).
:
ses = request.getSession(true); ses.setAttribute("Name","Value");
to retrieve:
request.getSession(false).getAttribute("name")
getSession (true) means creating a session if it does not exist. getSession (false) equals getSession. Finally, if you want to remove the attribute from the session from this point, you can use
request.getSession () removeAttribute ("Name") ;.
I hope this makes sense to you if you need to take a closer look at the Java Set, Get and Remove Session Attributes .
Tomred
source share