Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

index.jsp file opens even when the <welcome-file-list> is not defined

I've written a simple dynamic web project in Eclipse Luna. In web.xml page I've removed the default welcome-file-list tag.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>indextest</display-name>
</web-app>

But the url http://localhost:8080/indextest/ still directs to index.jsp under 'WEB-INF' even after I've removed the tag welcome-file-list from web.xml. How it directs to index.jsp page though welcome-file-list is absent in web.xml?

like image 477
Rafaf Tahsin Avatar asked Sep 02 '15 08:09

Rafaf Tahsin


2 Answers

If you are using a Tomcat 7 instance, and are not specifying the welcome-file-list, the container (tomcat) is looking into his default, that is in /conf/web.xml in your tomcat instance.

These are the lines:

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file>     
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list>

I suggest not to change anything in the tomcat default, because your web application should not be dependent on the container that runs it. Instead, you should define your own welcome-file-list in your own web.xml. Hope this helps!

like image 130
Paolof76 Avatar answered Oct 01 '22 15:10

Paolof76


If there is no welcome list provided then the container will try to load the below files in the order defined:

  1. index.html
  2. index.htm
  3. index.jsp

Update: regarding tomcat

If no web.xml is provided in the application, the default web.xml($CATALINA_HOME/conf/web.xml) of Tomcat is supplied to the application. This deployment descriptor has the following lines:

<!-- -->
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure to include any of the default values that you wish -->
<!-- to use within your application. -->

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file>     
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list>

That is why the index.jsp is shown by default

Source for update: https://stackoverflow.com/a/17247947/1129313

like image 24
Garry Avatar answered Oct 01 '22 17:10

Garry