aspose file tools*
The moose likes Servlets and the fly likes Servlet Instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Instance" Watch "Servlet Instance" New topic
Author

Servlet Instance

Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi All,
How is the instance of servlet stored in the container ? Is it container-specific ??
TIA
MB


Malhar Barai
SOA & Java Book
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

What do you mean by stored? It exists in memory.


Groovy
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Instance
 
Similar Threads
ServletConfig where to get the details?
how to call destroy() method ?
JSP translated into a Servlet
ServletException
How Servlet Container creates an instance of your Servlet