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 are the steps that are involved in using the httpservlet class?
What is the importance of init() method in Servlet ?
Explain session tracking and its importance?
What is the major difference between servlet and applet?
What is load-on-startup in servlet?
Explain load on start-up and its importance?
What is difference between GenericServlet and HttpServlet?
How do you find out what client machine is making a request to your servlet
What is servlet interface?
how the HTML data stored in web server?
Explain the difference between get and post method in servlet?
Why do we need servlet filter?
What are the common methods that are included in the http servlet class?
What is difference between cookies and httpsession?
What is the procedure of invoking different servlet in a different application?