This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes jsp/servlet reading directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp/servlet reading directory" Watch "jsp/servlet reading directory" New topic
Author

jsp/servlet reading directory

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi,
I'm creating a web page that reads a directory using either servlets or jsp. I know how to read a directory using command line java, but how do I read a directory (file names) using either a servlet, or jsp. Thanks
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Hi,
It's pretty much the same thing as what you did with the command line.
Create an instance of java.io.File on a particular directory and then call its list() or listFiles() method.
James.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
... and this is a useful way of getting the actual (local) path that is equivalent to a specific URI.
String realPath = pageContext.getServletContext().getRealPath(uri);
File f = new File(realPath);
[where uri is something like "/index.html", "/WEB-INF/myconfig.xml", etc]
This is useful as it stops the need to reference local files in your webapp as (for example) c:\jakarta-tomcat-4.0\webapps\mywebapp\...
Regards
Simon
[This message has been edited by Simon Brown (edited August 28, 2001).]
kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
I'm still having problems. I have a program that works from the command line, but how to you convert from the use of the "String[] args" in main?
 
GeeCON Prague 2014
 
subject: jsp/servlet reading directory