>>> "Peters, Jim" <[EMAIL PROTECTED]> 07-Jun-00 4:37:38 PM >>>
>I would like to display the contents of a directory as links.
>I think I have a perl script to do this, but am unfamiliar with
>these. My app is java servlets, jdbc, and javascript and I
>would like to keep it that way.
>Any help (example code) would be appreciated !
public void doGet(...
{
....
//work out what the path of the directory to look at is...
...
File directory=new File(directorypath);
String[] fnames=directory.list();
PrintWriter out=response.getWriter();
response.setContentType("text/html");
out.println("<html><body>");
for(int i=0; i<fnames.length; i++)
{
out.println("<a href=\"");
out.println(fnames[i]);
out.println("\">");
out.println(fnames[i]);
out.println("</a><br>");
}
out.println("</body></html>");
out.close();
}
And that's that. You may have to play around with the contents of the
HREF depending on where you want the request to come back to. That
depends on how you want the directory to be accessed in the first
place.
One strategy is to use the path info as the directory path... but
that is not necessarily what you want.
Nic Ferrier
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html