【JSP开源代码栏目提醒】:网学会员为需要JSP开源代码的朋友们搜集整理了ex9_07.jsp相关资料,希望对各位网友有所帮助!
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%--带过滤功能的目录遍历--%>
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>JSP通用范例大全</title>
</head>
<body>
<center><font size=5>带过滤功能的目录遍历</font></center>
<br><hr><br>
<%
class PostfixFilter implements FilenameFilter{
String str=null;
public PostfixFilter(String postfix){
str="."+postfix;
}
public boolean accept(File dir,String name){
File file=new File(dir,name);
if(file.isDirectory())
return false;
return name.toLowerCase().endsWith(str.toLowerCase());
}
}
String path=request.getRealPath("/");
File dirName=new File(path);
PostfixFilter filter=new PostfixFilter("jsp");
File list[]=dirName.listFiles(filter);
%>
在<%=dirName.getAbsolutePath()%>目录下的JSP文件有:
<br>
<ui>
<%for(int i=0;i<list.length;i++){%>
<li><%=list[i].getName()%></li>
<%}%>
</ui>
</body>
</html>