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 the functionality of actionservlet and requestprocessor?
Tell us something about servletcontext interface.
How can we perform any action at the time of deploying the project?
Are Servlets Thread Safe? How to achieve thread safety in servlets?
Is servlet synchronized?
What is servlet attributes and their scope?
What is difference between PrintWriter and ServletOutputStream?
What is session tracking?
Is servlet a server side scripting language?
How to notify an object in session when session is invalidated or timed-out?
What is the difference between the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?
Which method is called when reference variable is passed in system.net?
What do you mean by request dispatcher in servlet?
Can you call a jsp from the servlet?
What is called servlet container?