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 meant by a servlet?
What is java servlet?
What is a generic servlet?
What is the workflow of a servlet?
How can we perform any action at the time of deploying the project?
What is servlet collaboration?
Does servlet have main method?
What are the life cycle methods of a servlet?
Write a program to show the functionality of doget and dopost method?
What are the uses of servlets?
Explains the differences between context.getrequestdispatcher() and request.getrequestdispatcher()?
How do I know if java is running on linux?
Explain url encoding in servlet?
Which HTTP method is non-idempotent?
What is the use of send redirect () method?