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 the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?
What are the kinds of http requests?
What do you mean by scope object and what are its types?
Can a jsp be called using a servlet?
List the Different types of servlet?
Explains the differences between context.getrequestdispatcher() and request.getrequestdispatcher()?
Is java servlet still used?
What is the main purpose of java servlets?
What is new in ServletRequest interface ? (Servlet 2.4)
How httpservlet is different from the genericservlet?
What is meant by session? Tell me something about httpsession class?
Explain servlet life cycle?
How can we create deadlock situation in servlet?
What are the difference between session and cookies in servlet? Explain
Can you send an authentication error from a servlet?