Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the use of this servlet?

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we have <servlet> tag for it but don't have <servlet-mapping> tag.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same as having a method and not calling
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic