如何获得Tomcat的ROOT/index.jsp页面列出所有Web应用程序? [英] How do I get Tomcat's ROOT/index.jsp page to list out all webapps?
问题描述
我来自php环境,正在尝试移至Tomcat/jsp.
I'm from a php environment and trying to move to Tomcat/jsp.
我习惯于将Web服务器指向一个目录并获得所有文件夹的自动列表.
I'm used to being able to point my web server at a directory and getting a nice automatic listing of all my folders.
我意识到Tomcat不能那样工作,但是我想让它对我的开发和原型环境那样工作.
I realize Tomcat doesn't work that way, but I'd like to make it work that way for my development and prototyping environments.
我的目标是,当我将新的Web应用程序添加到CATALINA_HOME时,ROOT/index.jsp页面应列出新的Web应用程序以及已安装的任何其他应用程序.
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.
使用此目录结构
ROOT/index.jsp
sample/index.jsp
anotherApp/index.jsp
当我访问localhost:8080时,我想在浏览器中看到类似的内容:
I'd like to see something like this in my browser when I visit localhost:8080:
My Web Apps:
* sample
* anotherApp
是否有一种简单的方法来构建循环遍历tomcat.availWebApps并为每个链接建立链接的循环?
Is there a simple way to build a loop that iterates over tomcat.availWebApps and makes a link for each one?
推荐答案
嗯,这可行.它完全是手动的.如果有人知道自动或清洁的方法,我很想知道.
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>
这篇关于如何获得Tomcat的ROOT/index.jsp页面列出所有Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!