Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2003, 01:23 PM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Directory Listing

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

 
Old September 20th, 2003, 06:25 PM
Registered User
 
Join Date: Sep 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yasir_lahham
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing of Directory Content ram_dwivedi Javascript 3 December 9th, 2005 05:13 AM
Ch. 10 Directory listing superkooi BOOK: Beginning ASP 3.0 1 March 3rd, 2005 07:39 AM
network directory listing using FileSystemObject? wyvern47 Classic ASP Components 1 December 15th, 2004 12:09 PM
FSO directory listing spinout Classic ASP Components 4 November 7th, 2004 03:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.