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


Please Help Members By Posting Answers For Below Questions

Why HttpServlet class is declared abstract?

873


What is the servletconfig object?

756


When servlet is loaded?

801


What is cookie in servlet?

786


What do you mean by the servlet chaining?

787


What's the advantages using servlets than using cgi?

736


What are the kinds of http requests?

800


What is servlet? Explain

782


When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

783


What’s the use of the servlet wrapper classes??

846


What is meant by cookies?

845


What are different ways for authentication of servlet?

735


What is pure servlet?

926


how many jsp scripting elements are there and what are those?

798


When is the servlet instance created in the life cycle of servlet? What is the importance of configuring a servlet?

791