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
How do you create a cookie using servlet?
What is Request Dispatcher?
What is string tokenizer?
What is the servletconfig object?
Can you use javascript in servlets?
Which event is fired at the time of setting, getting or removing attribute from application scope?
What is the functionality of actionservlet and requestprocessor?
How does java thread pool work?
How many servlet objects are created?
What are the different methods of session management in servlets?
When a client request is sent to the servlet container, how does the container choose which servlet to invoke?
What is servlet collaboration?
What is a cookie What is the difference between session and cookie
What are the jobs performed by servlets?
What is servlet interface?