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

Explain their methods? Tell me their parameter names also have you used threads in servlet?

670


what is servlet chaining?

712


What are the types of protocols supported by httpservlet ?

791


When servlet object is created?

690


How forward () method is different from send redirect () method?

603






How to read request headers from servlets?

656


Explain the servlet context.

689


What is the major difference between servlet and applet?

609


What is servlet and its use?

716


Write all the phases defined in servlet life cycle?

660


What is the inter-servlet communication?

791


What is the workflow of a servlet?

796


What are important features of Servlet 3?

678


why we should override only no-agrs init() method.

743


How to get the server information in a servlet?

766