Display Project/Directory listings in Tomcat Home Page

How to display a list of all applications deployed inside the Tomcat Webapps folder

By default the ROOT application index file in Tomcat has the Tomcat Home Page. But if you want to display a List of all the applications hosted in the webapps folder for that Tomcat Instance then create a project named ROOT in eclipse and change the index.jsp to the following code. After that just Export a WAR file named ROOT.war into the webapps directory.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ page import="java.io.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Your application Title</title>

<div id="allContent">
    String root = getServletContext()
    String ignored = "ROOT";
    java.io.File file;
    java.io.File dir = new java.io.File(root);
    String[] list = dir.list();

    for (int i = 0; i < list.length; i++) {
        file = new java.io.File(root + list[i]);
        if (file.isDirectory() &&
            ) {
             <a href="/<%=list[i]%>/" target="_top"><%=list[i]%></a>

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.