How to Set Index File of a Web-based Java Application using JSP

This is an article which is just written to show how to set index of of a web-based Java application. In this case, it is a simple web-based Java application using JSP (Java Server Pages) as its main web-based programming language. The main purpose writing this article is the successful of setting the index file of the web-base Java application.

Basically, every web-base Java application need to be executed in a Java-based Application Container like Tomcat Apache Webserver or a Java-based Application Server such as JBoss, Websphere, etc. But how can those Java-based Application Container or Java-based Application Server knows what file to be executed at the first time when the Java-based Application Server is being requested by typing the associate URL of the Java-based Application Server itself.

Normally, those Java-based Application Container or Java-based Application Server will follow the rule which has been defined in a file server as an application descriptor. Usually, because the term of deployment of the application itself, it is called the application deployment descriptor and it is generally created with the name of web.xml. It is an XML file with the structure already firmed by the definition of the namespace located in the header of the XML file itself. The file itself will be placed in the WEB-INF folder inside the application source source.

In order to define the first file for being executed after the web-based Java application is being requested through any kinds of media normally web-browser, just add the following line of configuration inside the web.xml file :

As shown in the above line of configurations, the file which is going to be executed at first is ‘index.jsp’. It is indicated as the value of the attribute of welcome-file tag listed inside the tag welcome-file-list. It can also defined more than one where the order of the execution will be executed from the top of the list. If the file cannot be found, it will then search the second file listed in the configuration. For an example shown below :

Based on the configuration above, the file executed in the order of ‘index.htm’. In the case of the file doesn’t exist in the application source code, it will look for index.html and then index.jsp.

Don’t forget to restart either turn off and then start the Java-based Application Container or Java-based Application Server so that the application deployment descriptor can be read and can be executed with the newly added configuration lines as shown above.