| Author |
What is the use of this servlet?
|
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
|
If we have <servlet> tag for it but don't have <servlet-mapping> tag.
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
|
Same as having a method and not calling
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Before the addition of ContextListeners in Servlet Spec 2.3, people would often create one servlet solely for the purpose of initializing the application (all initialization code would go in the servlet's init method). The <load-on-startup> element in the deployment descriptor would cause the servlet to be loaded when the app starts. Often these servlets wouldn't override any service methods and thus have no need for a url-mapping.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Jaime M. Tovar
Ranch Hand
Joined: Mar 28, 2005
Posts: 133
|
|
|
I also have seen it as a way of having a timer in your app. You create a servlet that loads configuration from a file and refresh app config every certain time, but as you need the first calling you use the load-on-start to start it. Then the servlet will do its work every certain time afterwards. I think some log4j tutorials use this kind of servlet to do the autorefresh configuration from a properties file.
|
She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
|
 |
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
Originally posted by Ben Souther: Before the addition of ContextListeners in Servlet Spec 2.3, people would often create one servlet solely for the purpose of initializing the application (all initialization code would go in the servlet's init method). The <load-on-startup> element in the deployment descriptor would cause the servlet to be loaded when the app starts. Often these servlets wouldn't override any service methods and thus have no need for a url-mapping.
I thought, this <load-on-startup> tag is for container to know, how many instance it can create for this servlet... What kind of (and how many) values it can have and what does those value mean? In my application, it is 1... Thanks.
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
I thought, this <load-on-startup> tag is for container to know, how many instance it can create for this servlet... What kind of (and how many) values it can have and what does those value mean? In my application, it is 1...
The load-on-startup element indicates that a servlet should be loaded on the startup of the web application. This element can take an integer value which indicates the order in which the servlet should be loaded. If the value is negative, or if this element is not present, the container is at its will as to when it should load the servlet. If the value is a positive integer or 0, the container must load and initialize the servlet when the application is deployed. Generally the servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.
|
 |
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
Originally posted by vidya sagar: The load-on-startup element indicates that a servlet should be loaded on the startup of the web application. This element can take an integer value which indicates the order in which the servlet should be loaded. If the value is negative, or if this element is not present, the container is at its will as to when it should load the servlet. If the value is a positive integer or 0, the container must load and initialize the servlet when the application is deployed. Generally the servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.
Thanks Vidya. Means, if <load-on-startup> is -ve or not present, then <url-mapping> tag is must to access that servlet. And one which has 0 will be loaded before than one which has 1 or more <load-on-startup> Right??
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
Means, if <load-on-startup> is -ve or not present, then <url-mapping> tag is must to access that servlet. And one which has 0 will be loaded before than one which has 1 or more <load-on-startup> Right??
Yes
|
 |
 |
|
|
subject: What is the use of this servlet?
|
|
|