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?
Answers were Sorted based on User's Feedback
Answer / mohit rana
It's simple just use session (session object).
HttpSession session = request.getSession();
session.setAttribute(String obj);
and get the above value on other container
session.getAttribute(String obj);
Is This Answer Correct ? | 16 Yes | 5 No |
Answer / 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 |
Answer / karnakar thallapalli
Generally we use session binding listeners
your class must implements HttpssionBindingListenre(not suer class name) and and implement its methods..............
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / animesh kumar
Session Values Can Be passed from one servlet container to
another in FOUR ways :
1. URL rewriting
2. Hidden Form Fields
3. Cookies
4. Using a session Object
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / vemula bojjanna
by using setAttribute()and getAttribute()
for example list is one variable in one servlet like
List l=new list();
l.add("bujji");
l.add("vemula");
u set this value from this servlet by using
req.setAtribute("list",l);
by using getAtribute() u can use the list value of first
servlet into second servlet like
req.getAtribut(list);
Is This Answer Correct ? | 3 Yes | 14 No |
What are the life-cycle methods for a servlet?
I have a requirement Here we have a ResultSet object that will contain 50 records i need to print those recors in to a webpage(i.e; view according to MVC architectures that mybe servlet or jsp) . Here i need to print the records 10 per page that is 1 to 10 in page one and 11 to 20 in page two like remaining will be appeared in other pages we need to display those page numbers whenever we click on that page number we will go to that page and display 10 records like we will display 5 pages it is like this << 1 2 3 4 5 next >>
how JSP can extend servlet or interface ...?
How we can call a jsp from the servlet?
What do you understand by mime type?
What exactly are the functions of servlet?
When should you prefer to use doget() over dopost()?
How to debug a servlet?
What is the difference between context parameter and context attribute?
when the webcontainer creates ServeletConfig,ServletContext objects? befoure creating the Servlet object or not?
Given the request path below, which are context path, servlet path and path info?
What is a Session Id?