Issue
I am trying to create a booking form that needs the User ID in all the pages. I wanted to know how to handle session when I redirect the pages as [HTML->servlet->HTML]
Solution
You can used HttpSession.setAttribute & HttpSession.getAttribute for eg:
JSP Page :
//getting id value
String id= request.getParameter("user_id");
//the variable which is set in session scope you can use anywhere
request.getSession().setAttribute("id",id);
request.getRequestDispatcher("/yourServleturl").forward(request,response);
Now to get that session
attribute write like below in servlet
:
HttpSession session=request.getSession();
//getting value in session
String id=session.getAttribute("id").toString();
//do further processing
Hope this helps !
Answered By - Swati