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 MIME Type?
What is servlet? Explain
Write the code to get the server information in servlet.
What do you mean by web applications? Explain web application directory arrangement?
How the JSP file will be executed on the Server side?
Explain how does JSP handle run-time exceptions?
What is the major difference between servlet and applet?
How do you invoke a Servlet? What is the difference between doPost method and doGet method?
Differentiate between the print writer and servlet output stream?
What exception should be thrown when servlet is not properly initialized?
What is the use of httpservletrequestwrapper and httpservletresponsewrapper?
Why the concept of single thread model interface is used?
What is a servlet context object?
Explain the war file?
Explain the servlet filter.