遍历你项目下的文件和文件夹结构,并可以依次展开,便于开发时快速定位
<%--
把这个页面放到你的项目的WebRoot任意目录下,访问该页面你可以看到你项目的WebRoot下的整个文件目录结构,不可以快速访问它们
@version $Date: 2012-10-19 20:49:39
@author WangJun
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title><%=path.substring(1, 6)%>页面导航</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body {
margin: 0 auto;
padding: 0;
width: 980px;
}
#header {
width: 980px;
height: 45px;
margin-bottom: 5px;
}
#title {
margin: 5px auto;
font-size: 5ex;
font-weight: normal;
float: left;
}
#content {
padding: 25px 55px;
border: thin inset;
text-decoration: none;
}
ol {
line-height: 3.6ex;
}
#url,#directory {
width: 435px;
display: table-cell;
}
#url li,#directory li {
display: list-item;
}
#foot {
color: green;
text-align: right;
}
</style>
</head>
<body>
<div id="header">
<span id="title">PKSoft Study</span>
</div>
<hr>
<div id="content">
<h3>页面导航</h3>
<hr>
<%
String dir = request.getParameter("dir");
if (dir == null)
dir = "/";
else
dir = "/" + dir;
Set<String> urls = (HashSet<String>) this.getServletContext()
.getResourcePaths(dir);
String webRootUrl = "";
String webRootDirectory = "";
for (String url : urls) {
if (url.indexOf(".") >= 0 || url.indexOf(".") >= 0)
webRootUrl += "<li><a href='" + url.substring(1) + "'>"
+ url.substring(1) + "</a></li>";
else
webRootDirectory += "<li><a href='index.jsp?dir="
+ url.substring(1) + "'>" + url.substring(1)
+ "</a></li>";
}
out.print("<div id=\"url\"> <h5>文件</h5><ol>" + webRootUrl
+ " </ol></div>");
out.print("<div id=\"directory\"><h5>文件夹</h5><ol>"
+ webRootDirectory + "</ol></div>");
out.flush();
%>
<br> <br> <br>
</div>
<div id="foot">copyright WangJun</div>
</body>
</html>