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
Should I override the service() method?
What is the use of welcome-file-list?
How do you run a servlet?
Explain url encoding?
Describe servlet?
What is the
Write the code to get the server information in servlet.
What are the common methods that are included in the http servlet class?
How do you find out what client machine is making a request to your servlet
Can we get PrintWriter and ServletOutputStream both in a servlet?
List the Different types of servlet?
Are Servlets Thread Safe? How to achieve thread safety in servlets?
What is servlet initializer?
How can we refresh automatically when new data is entered into the database?
Explain session tracking and its importance?