How to pass session values from one servlet container to another servlet container? or how can we get session values of one container in another container?
Answer Posted / satishkumar vishwakarma
We can Pass Session value from servlet container to another
with the help of Session Object
E.g. I have two Servlet named ServletA and ServletB if i
want to pass value from ServletA to ServletB using Session
Object.
i.e. HttpSession session = request.getSession();
//Now i want to pass my name from ServletA to ServletB
String s = "Satishkumar V";
session.setAttribute("myname",s);
//Now i want to display this name in ServletB Then we will
write the following code in ServletB
HttpSession session = request.getSession();
String s = (String)session.getAttribute("myname");
//Now we can display the value of s in anywhere in Servlet B
out.println("<h1>"+s+"</h1>");
| Is This Answer Correct ? | 10 Yes | 1 No |
Post New Answer View All Answers
What is the difference between CGI and Servlet?
Servlet is pure java object or not?
What is MIME Type?
What is the use of send redirect () method?
Which method of the httpservletrequest object is used?
Why do we have servlet wrapper classes?
What are the life cycle methods of the servlet?
Why is http protocol called as a stateless protocol?
What is difference between PrintWriter and ServletOutputStream?
What is the procedure of invoking different servlet in a different application?
What do you mean by deployment descriptor?
What is lazy loading and what is Generic Servlet Class?
What is the GenericServlet class?
What is servlet api used for conneting database?
Explain the difference between servlet and cgi?