How can I share objects across different sessions?
Answer Posted / sanjeev kumar
Information (It can be primitives or objects) can be shared
across different servlets in 3 ways in J2EE.
1) Request object-- If the data need to be shared with in
the request scope we can set it on request object with
request.setAttribute() method. And can be accessed from the
other servlet or JSP with request.getAttribute() method.
2) Session object-- If the data need to be shared with in
the session scope we can set it on session object with
session.setAttribute() method. And can be accessed from the
other servlet or JSP with session.getAttribute() method.
3) Context object-- If the data need to be shared with in
the context (Application) scope we can set it on context
object with context.setAttribute() method. And can be
accessed from the other servlet or JSP with
context.getAttribute() method.
| Is This Answer Correct ? | 16 Yes | 4 No |
Post New Answer View All Answers
What is a web container and what is its responsibility?
Explain url encoding in servlet?
What is servlet instance?
what is multiple server?
How do you get the ip address of the client in servlet?
What is difference between get and post method?
request parameter how to find whether a parameter exists in the request object?
What is the process for chaining servlet?
Whether thread can be used in servlets?
Explain the concept of ssi ?
Can you use javascript in servlets?
Explain mvc pattern.
What is http servlet? Explain with the help of an example.
Why jsp is better than servlet?
What are the common methods that are included in the http servlet class?