Saturday, June 20, 2020

State the Home Page in a Java Web Project Using the web.xml welcome-file-list

The web.xml contains the Java server web serving instructions. And the <welcome-file-list /> states the files that will loaded if no page is declared when you're loading a site.  

Default Configuration
The default configuration loads pages in order of priority stated. And when nothing is found it will respond with a 404. 

Default Load Priority
1. index.html
2. index.html
3. index.htm
4. index.jsp

Example of the default WEB-INF/web.xml webapp config.
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

	<!-- No <weclome-file-list/> stated for the default config -->

</web-app>

Usage
Add the welcome-file-list tag element to your web-app element and state the pages you would like to load as your home page when no page is declared like the configuration below.

Load My Pages in Order of:
1. index.html
2. index.jsp
3. home.jsp
4. help.jsp

Example of stating your own WEB-INF/web.xml welcome-file-list. 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

	<!-- Make your own welcome-file load priority -->
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>home.jsp</welcome-file>
        <welcome-file>help.jsp</welcome-file>
    </welcome-file-list>

</web-app>

No comments:

Trying out the Dart Analysis Server

I wanted to see how the Dart Analysis Server was put together and worked. I started looking to see how I could wire it up and try out the co...