SimplGy
SimplGy

Reputation: 20437

How do I get Tomcat's ROOT/index.jsp page to list out all webapps?

I'm from a php environment and trying to move to Tomcat/jsp.

I'm used to being able to point my web server at a directory and getting a nice automatic listing of all my folders.

I realize Tomcat doesn't work that way, but I'd like to make it work that way for my development and prototyping environments.

My goal is that when I add a new web application to CATALINA_HOME, the ROOT/index.jsp page should list out the new web application as well as any other applications already installed.

given this directory structure

ROOT/index.jsp
sample/index.jsp
anotherApp/index.jsp

I'd like to see something like this in my browser when I visit localhost:8080:

My Web Apps:
* sample
* anotherApp

Is there a simple way to build a loop that iterates over tomcat.availWebApps and makes a link for each one?

Upvotes: 1

Views: 4286

Answers (2)

rickz
rickz

Reputation: 4474

Tomcat comes with a Manager app. Look at your Tomcat's home page(at http://localhost:8080/). There is a button on that page that is labeled "Manager App". You can set up your name, role and password. See http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

Upvotes: 1

SimplGy
SimplGy

Reputation: 20437

Well, this works. It's totally manual though. If someone knows an automatic or cleaner way to do this, I'd love to know.

<!DOCTYPE html>
<html>
<head>

</head>
<body>
    <h2>Eric's Tomcat Webapps</h2>
    <ul>
    <%
    String root="/Users/eric/www/_Deployed Tomcat/";
    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() &&
            !list[i].equals(ignored)
            ) {
        %>
            <li><a href="<%=list[i]%>" target="_top"><%=list[i]%></a><br>
        <%
        }
    }
    %>
    </ul>

</body>
</html>

Upvotes: 0

Related Questions