Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

accessing files/dirs on my website (tomcat0

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic