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 Difference between doGet() and doPost()?
What are the phases of a servlet life cycle?
How can we invoke another servlet in a different application?
What is the procedure for initializing a servlet?
Why is a constructor needed in a servlet even if we use the init method?
What are the types of protocols supported by httpservlet ?
Explain Action Servlet?
Explain the servlet filter.
Is servlet a server side scripting language?
Is servlet thread safe?
Why HttpServlet class is declared abstract?
Explain the differences between jsp and servlet.
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
What are the different session tracking techniques?
When to use doget() and when dopost()?