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


Please Help Members By Posting Answers For Below Questions

What is meant by a servlet?

773


What is java servlet?

778


What is a generic servlet?

674


What is the workflow of a servlet?

881


How can we perform any action at the time of deploying the project?

849


What is servlet collaboration?

854


Does servlet have main method?

881


What are the life cycle methods of a servlet?

762


Write a program to show the functionality of doget and dopost method?

862


What are the uses of servlets?

782


Explains the differences between context.getrequestdispatcher() and request.getrequestdispatcher()?

722


How do I know if java is running on linux?

769


Explain url encoding in servlet?

771


Which HTTP method is non-idempotent?

784


What is the use of send redirect () method?

767