• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused, please help !!!  RSS feed

 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using the File API inside a Servlet, but it's not working.

What i want to do is to list some files in a folder inside WEB-INF, and I'm trying the following code :


But it's not working

Can anybody guide me through the right way to point to specific folder inside tomcat ?

Thanks in advance ...
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File webFormssDirectory = new File("/WEB-INF/webForms");

I guess there is something wrong with the bold portion of your code.
'/' means the context root for web application , how will the core api know about that ?

I think you have to use the absolute path.One more thing is , how will this behave in which the application is not unjared by the container.
[ May 28, 2007: Message edited by: Rahul Bhattacharjee ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A path starting with "/" means the root of the file system hierarchy, which is not what you want. You were probably assuming that it meant the root of the web application, but it doesn't work that way.

Something like

would work, unless the web app is part of an unexploded war file.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
A path starting with "/" means the root of the file system hierarchy


Is this true for windows or only in case of UNIX?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/ does work in Windows, at least in newer JVMs: it refers to the root of the current hard disk on which your application is running.

To refer to the original post, you'll want to use the following:
This will return all resources in the application which start with "/WEB-INF/webForms/". You can use regex to further restrict those results from the return set, for example if you don't want all sub-directories included.

Other methods of use to you might be getResource(String) returning a URL to the resource, and getResourceAsStream(String) which returns an InputStream. These are all independent of the file system and will work even for resources contained in a WAR. In any case, further discussion belongs in Servlets...
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked guys, thanks alot ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!