• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp/servlet reading directory

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... 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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic