Welcome file and load on start up in detail
welcome-file-list tag gets define inside web.xml deployment descriptor file. This tag is responsible to load a file as soon as server starts up running.
Creation of Dynamic Web Project by default generates below web.xml having default content as mentioned in below screenshot.
Below is the sample webl.xml file having <welcome-file-list> tag:
<welcome-file-list> tag contains multiple <welcome-file> tags under which we can provide file with below extensions:
- index.html
- index.htm
- index.jsp
localhost:<port_number>/project_name will by default load index.jsp file as soon as server starts.
e.g. http://localhost:8082/ServletDemo/
load-on-startup
load-on-startup tag gets define inside web.xml deployment descriptor file. This tag is responsible to load a servlet as soon as server starts up running and call init() method at the same time.
Below is the sample webl.xml file having <load-on-startup> tag:
<servlet> tag contains <load-on-startup>, <servlet-name> and <servlet-class> tags.
We can define multiple <servlet> tags having unique values for <load-on-startup>, <servlet-name> and <servlet-class> tags.
<load-on-startup> tag can have positive, zero on negative value.
The servlet with the lowest integer value will get loaded first. For example, suppose we have three <load-on-startup> tags in web.xml with values of -3, 0 and 2, respectively. As mentioned earlier, the servlet having the lowest value of -3 will load first. After that, it will load 0 and then 2.
Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.