Subject: Directory Listing
Posted By: Bleetz Post Date: 7/21/2003 1:23:34 PM
Hi everybody, just one quick question.

I want to do a directory listing with jsp using tomcat. Any way I can do this?

Best regards

Reply By: yasir_lahham Reply Date: 9/20/2003 6:25:36 PM
save the following code to a jsp page, name it Jsp1.jsp, then execute it using tomcat,
offcourse it's primitive, but I hope it will help,

<%@ page import="java.io.*"%>
<html>
<head>
<title>
Directory List
</title>
</head>
<body>
<%
String fileName=request.getParameter("fileName");
if (fileName==null) fileName="c:/";
fileName=fileName.trim();
%>
<form method="post">
<%File file=new File(fileName);
File sons[] = file.listFiles();
for(int i=0;i<sons.length;i++){
out.println("<br>");
if (sons[i].isDirectory())

out.println("<a href='Jsp1.jsp?fileName="+sons[i].toString().replace('\\','/')+"'>"+sons[i]+"</a>");
else
out.println(sons[i]);
}
%>
</form>
</body>
</html>

MHD Yasir Al-lahham

Go to topic 4359

Return to index page 1042
Return to index page 1041
Return to index page 1040
Return to index page 1039
Return to index page 1038
Return to index page 1037
Return to index page 1036
Return to index page 1035
Return to index page 1034
Return to index page 1033