You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chip Paul <ch...@ethreat.com> on 2003/06/12 00:14:11 UTC

Contents of directory on server?

I've seen the posts on the list realted to reading in a file (usually xml)
via getResourceAsStream(), but was wondering how to iterate over the
contents of a directory located inside the war file.

Has anyone done this without an xml/properties file to map the locations?

The specific application is to iterate through a directory and produce links
to resources located in it.

Chip


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Contents of directory on server?

Posted by James Norman <jn...@taregon.com>.
You can always call servletContext.getRealPath() then create a File and list
the contents.  This however would require that your war be unpacked, and is
not good practice.  You could maybe define the location of the war file on a
init-param of web.xml, then at startup build an index of the war file with
the java.util.zip classes.  The easiest way would be to just unpack the war
file.  This does come with its consequences, you cant use the Tomcat deploy
tasks if the war has to be unpacked.  No easy answer.

-james

----- Original Message -----
From: "Chip Paul" <ch...@ethreat.com>
To: "Struts User" <st...@jakarta.apache.org>
Sent: Wednesday, June 11, 2003 4:14 PM
Subject: Contents of directory on server?


> I've seen the posts on the list realted to reading in a file (usually xml)
> via getResourceAsStream(), but was wondering how to iterate over the
> contents of a directory located inside the war file.
>
> Has anyone done this without an xml/properties file to map the locations?
>
> The specific application is to iterate through a directory and produce
links
> to resources located in it.
>
> Chip
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Contents of directory on server?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 11 Jun 2003, Chip Paul wrote:

> Date: Wed, 11 Jun 2003 17:14:11 -0500
> From: Chip Paul <ch...@ethreat.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      chip@ethreat.com
> To: Struts User <st...@jakarta.apache.org>
> Subject: Contents of directory on server?
>
> I've seen the posts on the list realted to reading in a file (usually xml)
> via getResourceAsStream(), but was wondering how to iterate over the
> contents of a directory located inside the war file.
>
> Has anyone done this without an xml/properties file to map the locations?
>
> The specific application is to iterate through a directory and produce links
> to resources located in it.
>

On a Servlet 2.3 container, you can use ServletContext.getResourcePaths()
to list all the paths in a particular "directory" of your webapp, even if
the application is run directly from a WAR file.  On a pre-2.3 container,
the best you can do is try ServletContext.getRealPath() and then make
assumptions about the paths of related files, but this is definitely not
portable.

> Chip

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org