Brij Naald wrote:
Hi, I want to list all the files in a directory. How do I start this? I assume I have to make an action: <action path="/List" type="app.ListAction" name="evaluatieForm"> <forward name="success" path="/pages/ListFiles.jsp"/> </action>
The action then creates an array of Strings (so String[]).
and puts it in the request (so request.setAttribute("files",stringArray);)
Then I have to make the jsp-page which uses the strings to display the page.
Is this the correct way?
That would be fine. This assumes your application has permission to access the given part of the filesystem on the server box.
You could also set a reference to the File array that java.io.File.listFiles retrieves via request attribute. Then your JSP could invoke File methods on each instance in a loop created using c:forEach (JSTL) or logic:iterate (Struts) tags, to create a table equivalent to a directory listing. Perhaps it would be better to write a method that returned a Collection of instances of a true JavaBean, something like "FileDescription" (one instance per file), so that your Collection would be tag-friendly. Then you could build the table with stuff like "$fileDescription.name" and "$fileDescription.length", "$fileDescription.isDirectory", etc. (see c:out, bean:write and the newer way of using the JSP expression language without tags).
Hope that helps,
Erik
How can I access the array of strings from the Jsp-page?
Thanks a lot!
_________________________________________________________________
Heb je MSN WebMessenger al ontdekt? http://webmessenger.msn.com/?mkt=nl-be
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]