File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes when is a servlet actually loaded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "when is a servlet actually loaded" Watch "when is a servlet actually loaded" New topic

when is a servlet actually loaded

jayram joshi

Joined: Aug 05, 2000
Posts: 23
I have a very basic doubt about loading of servlets.When does a sevlet get loaded exactly?Is it loaded when the web server starts up or is it loaded when the server receives the first request for a specific servlet.Is there any way of controlling the exact timing of loading various servlets
Also ..if i want to load a certain servlet at startup how can i do that.I am using TOMCAT as my servlet engine.
lokesh reddy
Ranch Hand

Joined: Sep 15, 2000
Posts: 66
Hi Jayram,
Here let me clarify one thing.
Whenever a webserver receives a request from the client, and if it found it as a servlet, it redirects the request to the servlet container, the servlet container inturn sends the request to the appropriate servlet. So, the servlet gets loaded in the jvm the first times it gets request and remains there for some time, so whenever the next request comes it is readily available to serve it.
Yes, you can load a servlet as soon as u start webserver. I dont know how to do it in tomcat, but here are the steps, how you can do in java webserver 2.0.
1) type http://localhost:9090 at your browser address bar.
2) type user name and password.
3) select webservice.
4) select servlets tab.
5) select the servlet u wish to start as soon as webserver starts
6) In the configuration panel select load at start up option.
Hope this info may be useful to you.
[This message has been edited by lokesh reddy (edited October 30, 2000).]
Preethi M

Joined: Oct 24, 2000
Posts: 22
Hai Jayram!
A servlet gets loaded when the server first receives request for the servlet.There is no way to control the exact time to load various servlets.
I know how to load a servlet at startup in Javawebserver2.0 I don't have knowledge regd Tomcat.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Servlet 2.2 spec specifies a "load-on-startup" tag in the deployment descriptor. If no load-on-startup is specified for a servlet, it is loaded when the servlet container feels like it, which is usually on the first request. If the servlet directive contains a load-on-startup it may optionally have an associated integer, indicating the position in the sequence of servlets to be started when the container starts.
Example 1: A servlet which is loaded on startup

Example 1: Two servlets, both loaded on startup, but "exampleFirst" is loaded first, and "exampleSecond" is loaded second.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: when is a servlet actually loaded
It's not a secret anymore!