Tomcat Welcome file list Tomcat directory listing setup welcome files in tomcat

Setup Welcome File List

When we type the URL till the project name only,we get the directory listing of the project folders.To avoid this we can setup the welcome files,which acts the the default welcome page when we type the url till project folder.We can use this facility provided by the tomcat folder when we want to display something like a login page or welcome page as the default or first page for the website and check other pages to be in session so that the user once logins then only he/she can traverse through different views of the site.The entry for the welcome file can be done in the delpoyment descriptor,i.e. Web.xml file .The sample is given below :

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

Here we can see that,when the url for till the project folder is hit in the browser,the welcome file is displayed.We can write as many welcome files in the <welcome-file-list> tag.The container first looks up for the first file to be present.If it exists it is displayed instead the container searches for the second entry.If not found it searches for the next page and so on till it finds one or els page not found error is thrown.However,to enable directory listing we can either edit the containers web.xml file which lies in the CATALINA_HOME/conf,or we can can edit our application specific web.xml file.In the server`s web.xml file we need to edit listings init param value for DefaultServlet entry as true.For the application specific purpose we need to override the DefaultServlet behaviour by making a sparate entry in the servlet tag for DeafaultServlet and making the listings init param as true.The snippet from the application`s web.xml file illustrates this:

<!-- Enable directory listings by overriding the server`s default web.xml file -->
<!-- The default servlet →

<servlet>
    <servlet-name>DefaultServletOverride</servlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
    <init-param>
        <param-name>listings</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Add a mapping for our new default servlet -->
<servlet-mapping>
    <servlet-name>DefaultServletOverride</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

It must be noted that the entry in the servlet-name tag for the DefaultServlet be different in the container`s web.xml file and the application`s web.xml file otherwise a conflict will occur.

Number of View :2559

Tags:

  1. No comments yet.

SetPageWidth
Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache