Hi all i have two servlet in the same app,i stored an attribute in the context object using setAttribute and i tried to retrieve it from the second servlet using getAttribute,i got null,even i casted it.methhods as the following: servlet1Context.setAttribute("name","this a test"); String str1=(String)servlet2Context.getAttribute("name"); thanks for the help.
Hi, Listen it works perfectly fine i have set it in one servlet and got it in second Servlet.Following is the code in init method. ServletContext servletContext = null; DatabaseConnection db = null; //DatabaseConnection is my defined class. servletContext = config.getServletContext(); db = servletContext.getAttribute("db") it works perfectly fine. Pls check your code again.In first servlet only try to get the object from context after setting it.See what do u get..?? I hope abv will help.
subject: setAttribute and getAttribute() with Context Object?