views:

51

answers:

1

I need to list files under a folder of a different web application. Is there a way to get this done without having to provide the actual path in a properties file?

Webapps
 - WebApp1
    -MyFolderOfInterest
 - WebApp2 
   - WEB-INF
     - Classes
       - MyClasstoListFiles

TIA

+3  A: 

Yes, in a servlet of yours:

getServletContext().getContext("/WebApp1").getResource("/MyFolderOfInterest")

The important things here is that you gain access to a ServletContext different than the one you are currently in. See the documentation of getContext()

And in order to make a context eligible for access from other contexts, for WebApp2 you need a context.xml (in META-INF, for example) that contains:

<Context crossContext="true" ... />
Bozho
I am guessing you meant getServletContext().getContext("/WebApp1").getResource("/MyFolderOfInterest") However, it looks like getResource returns an URL and not a file object that is needed for directory listing etc...
shikarishambu
did you make the context be `crossContext=true` ?
Bozho