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

What is called a session?

624


Hi frnd can i any one kindly can post for me portlet,hibernate and spring example application and with flow explantion configuration using Jdeveloper.and related links ar tutorials kindly please send me .its urgent for me .thanks in advance...........else can any one send to kondaiah.goddeti@gmail.com

1746


what do you understand by url rewriting?

548


What is servlet looping or chaining?

659


Tell us something about servletconfig interface.

584






What is a servlet?

610


Which java framework is most popular?

581


Explain the difference between get and post method in servlet?

607


What do you mean by servlet?

724


How servlet is created?

548


Explain the steps involved in placing a servlet within a package?

573


What are some disadvantages of storing session state in cookies?

592


What is cookies in servlet with example?

523


What is the capacity the doget can send to the server?

578


What is called servlet container?

666