• 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

accessing files/dirs on my website (tomcat0

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
File dir = new File("C:\\apache-tomcat-5.5.17\\webapps\\india\\delhi\
\images");

this works fine in my machine locally, but on my website.. if, say,
I'm in dir where 'images' dir is, this doesn't work...

File dir = new File("images")

starting @ root of webapp also doesn't work...

File dir = new File("/india/delhi/images");

names of directors are good, they are all lowercase...

have conditional to test...

if (imgsList == null)
out.println("null");

always prints 'null' on my website...

do paths in this constructor have to be absolute? so on my website
path would have to start with "http..."???

is this an access problem? all I want to do is count how many images are in 'images' dir..

thank you...
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Veronica Damian:

do paths in this constructor have to be absolute? so on my website
path would have to start with "http..."???



No to both of your questions. File can resolve relative paths. It does not take URL's of the format "http", but will take URL's of the format "file:". Are you deploying your app to a Unix server? They use different file path roots and seperators.

It is a Bad Idea to try to use hard-coded file locations in web applications. They are just too easy to break. javax.servlet.ServletContext has methods to obtain information about your deployment. Have a look and let us know what you find out.
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:


No to both of your questions. File can resolve relative paths. It does not take URL's of the format "http", but will take URL's of the format "file:". Are you deploying your app to a Unix server? They use different file path roots and seperators.

It is a Bad Idea to try to use hard-coded file locations in web applications. They are just too easy to break. javax.servlet.ServletContext has methods to obtain information about your deployment. Have a look and let us know what you find out.




yes but what separators do I need if dir I want is in current dir?

oh brother.. looking at javax.servlet.ServletContext you mentioned, not sure what method counts how many files in a dir..

thank you..
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Veronica Damian:

yes but what separators do I need if dir I want is in current dir?



I think you are confused. The current directory is always ".". No seperators necessary. Of course, the "current directory" for a web application is where the server is executing from, not from where your web app is deployed.


oh brother.. looking at javax.servlet.ServletContext you mentioned, not sure what method counts how many files in a dir..


You are getting ahead of yourself. ServletContext is a general-purpose class. The authors could not have anticipated every requirement, and if they did, the class would be so huge as to be unusable.
However, they do provide methods to, say, get the real path of a web resource, and that could prove useful in your situation.
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I asked guy at my webhosting, this is what finally worked:

/chroot/home/<myuid>/<mydomain>/tomcat/webapps/india/delhi/images



many thanks for yr help...
 
reply
    Bookmark Topic Watch Topic
  • New Topic