|
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
|