Get Session Id
In this example we are going to make a program in which we will find the session id which was generated by the container.
HttpSession session = request.getSession(); Inside the service method we ask for the session and every thing gets automatically, like the creation of the HttpSession object. There is no need to generate the unique session id. There is no need to make a new Cookie object. Everything happens automatically behind the scenes.
As soon as call the method getSession() of the request object a new object of the session gets created by the container and a unique session id generated to maintain the session. This session id is transmitted back to the response object so that whenever the client makes any request then it should also attach the session id with the requsest object so that the container can identify the session.
The code of the program is given below:
web.xml file for this program:
<?xml version="1.0" encoding="ISO-8859-1"?>
The output of the program is given below: