The load-on-startup element of web-app loads the servlet at the time of deployment or server start if value is positive. It is also known as pre initialization of servlet.
You can pass positive and negative value for the servlet.
Advantage of load-on-startup element
As you know well, servlet is loaded at first request. That means it consumes more time at first request. If you specify the load-on-startup in web.xml, servlet will be loaded at project deployment time or server start. So, it will take less time for responding to first request.
Passing positive value
If you pass the positive value, the lower integer value servlet will be loaded before the higher integer value servlet. In other words, container loads the servlets in ascending integer value. The 0 value will be loaded first then 1, 2, 3 and so on.
Let’s try to understand it by the example given below:
.... servlet1 com.javatpoint.FirstServlet 0 ... servlet2 com.javatpoint.SecondServlet 1
There are defined 2 servlets, both servlets will be loaded at the time of project deployment or server start. But, servlet1 will be loaded first then servlet2.
Passing negative value
If you pass the negative value, servlet will be loaded at request time, at first request.