How can I share objects across different sessions?

Answers were Sorted based on User's Feedback



How can I share objects across different sessions?..

Answer / 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

How can I share objects across different sessions?..

Answer / aman kumar

with the help of session.setAttribute()and session.getAtribute()we can share Httpsession object across different servlet and jsp.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More Servlets Interview Questions

My Question is that i am using <image> tag in my servlet and after compilation after that calling by url in my browser then images are not showing. Sometime images are showing and sometime is not showing. I am using Tomcat to run my servlets. Tell me if there any specification for image in servlets or what is solution for this ??

2 Answers  


What happens, if server sends a cookie to a browser that doesn't supports cookies?

2 Answers  


Write a command to get actual path of a servlet to the server?

0 Answers  


List out the difference between ServletConfig and ServletContext?

0 Answers  


What is context switching?

6 Answers  






difference between forward and sendredirect

6 Answers   Accenture,


What is cgi and what are its drawbacks?

0 Answers  


What is the process to implement doget and dopost methods?

0 Answers  


what is servlet life cycle?

3 Answers   Inforica,


What is the GenericServlet class?

0 Answers  


Which method of the httpservletrequest object is used?

0 Answers  


What is getservletcontext?

0 Answers  


Categories