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 the difference between Difference between doGet() and doPost()?

1002


What are the phases of a servlet life cycle?

868


How can we invoke another servlet in a different application?

957


What is the procedure for initializing a servlet?

779


Why is a constructor needed in a servlet even if we use the init method?

860


What are the types of protocols supported by httpservlet ?

967


Explain Action Servlet?

846


Explain the servlet filter.

763


Is servlet a server side scripting language?

850


Is servlet thread safe?

773


Why HttpServlet class is declared abstract?

910


Explain the differences between jsp and servlet.

756


In the servlets, we are having a web page that is invoking servlets ,username and password? which is checks in database? Suppose the second page also if we want to verify

809


What are the different session tracking techniques?

985


When to use doget() and when dopost()?

850