Storing a global object in servlet

Hi all,

I am trying to have a global object that can be shared with all the servlet.

One servlet will initialize this object and then on other servlet should be able to get reference to it.

How do I do this ??

Any sample code is appreciated.

Ramesh
Ramesh4uAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
Store it in the ServletContext instance.

To store:
getServletContext().setAttribute("abc", abc);

To retrieve:
MyObject abc = (MyObject) getServletContext().getAttribute("abc");
0
All Courses

From novice to tech pro — start learning today.