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 the functionality of actionservlet and requestprocessor?

601


Tell us something about servletcontext interface.

628


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

627


Are Servlets Thread Safe? How to achieve thread safety in servlets?

565


Is servlet synchronized?

609






What is servlet attributes and their scope?

598


What is difference between PrintWriter and ServletOutputStream?

781


What is session tracking?

700


Is servlet a server side scripting language?

559


How to notify an object in session when session is invalidated or timed-out?

638


What is the difference between the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?

571


Which method is called when reference variable is passed in system.net?

1838


What do you mean by request dispatcher in servlet?

616


Can you call a jsp from the servlet?

550


What is called servlet container?

669