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 MIME Type?

665


What is servlet? Explain

584


Write the code to get the server information in servlet.

575


What do you mean by web applications? Explain web application directory arrangement?

542


How the JSP file will be executed on the Server side?

646






Explain how does JSP handle run-time exceptions?

586


What is the major difference between servlet and applet?

544


How do you invoke a Servlet? What is the difference between doPost method and doGet method?

647


Differentiate between the print writer and servlet output stream?

565


What exception should be thrown when servlet is not properly initialized?

555


What is the use of httpservletrequestwrapper and httpservletresponsewrapper?

545


Why the concept of single thread model interface is used?

556


What is a servlet context object?

627


Explain the war file?

612


Explain the servlet filter.

542