This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Originally posted by Pradeep Bhat: What do you mean by stored? It exists in memory.
Well, The case is..I access a servlet, acc. to the lifecycle, #1. The container will first check for the instance of the servlet...??..How is this done ?? #2. If the instance is not present, the container loads the servlet class, and creates an instance & then the init() is called. So if the servlet is accessed again, it'll already find the instance, so init() wont be called again. So thats what my query was...will the instace be available after I access some other servlet & then again come back to that particular servlet.. TIA MB
The container looks at the request and the maps it has of web applications and associated servlets (via server.xml and web.xml). Following these maps it ends up with a servlet class that corresponds to the request. If this class has not been loaded, the container loads it, creates and instance, and calls the init() method. After the request has been handled, the instance will probably remain in memory to handle other requests, but this is NOT guaranteed. The servlet container is allowed to discard the instance if it wants to. Therefore, it is up to the programmer to make provision for storing any data that needs to be permanent. All of this is spelled out in the servlet API. Anybody working with servlets should go to this Sun site and download the servlet and jsp apis. Bill