Servlet – Load on startup
The element ‘load-on-startup‘ is used to load the servlet. The ‘void init()‘ method of servlet gets executed when the server gets started. The element content of ‘load-on-startup’ is Integer.
- if the integer is negative: The container loads servlet at any time.
- if the integer is 0 or positive: The servlet marked with lower integers are loaded before servlets marked with higher integers.
How to add element load-on-startup while mapping servlet?
The load-on-startup is the sub-attribute of servlet attribute in web.xml. We do mapping of servlet in web.xml file.
In XML file
ServletOne load first then ServletTwo get load.
Note: the above code is server-side code it will not work on online IDE (it is only for the clarification of the topic).