-
Jul 14th, 2011, 04:35 AM
#1
getting directory listing from Controller
Dear all,
I am new to Spring MVC, and in my first project, I want to show the user a list of html files, and let him choose one to look at. The html files are in the resources folder.
The controller needs to create a list of such files to pass to the JSP. How do I access the resources folder?
From other posts on this forum, and elsewhere, I have learned of several solutions, none of which I can get to work.
I can do this:
1) Have my controller implement ServletContextAware, and then get do this:
String path = this.servletContext.getContextPath();
2) Use a FileSystemResource like this
FileSystemResource r = new FileSystemResource("resources/");
None of these get me anywhere near the resources folder
Using both options, like this:
this.servletContext.getResourcePaths(rp);
System.out.println("rp:" + rp);
File dir = new File(rp.substring(1));
String s = dir.getAbsolutePath();
System.out.println("path:"+s);
FileSystemResource r = new FileSystemResource("resources/");
String s2= r.getDescription();
System.out.println("s2"+ s);
Under STS server, I get this:
path:C:\Program Files\springsource\sts-2.7.0.RELEASE\Spring1\resources
s2file [C:\Program Files\springsource\sts-2.7.0.RELEASE\resources]
and C:\Program Files\springsource\sts-2.7.0.RELEASE does not even contain my Spring1 project, let alone a resources folder.
What am I doing wrong?
Thank you for your attention.
-
Jul 14th, 2011, 06:08 AM
#2
Use [ code][/code ] tags when posting code 
You have the file now use it... I suggest looking at the API of the file object... I suggest using the listFiles method, which gives you the content of the directory...
-
Jul 14th, 2011, 06:21 AM
#3
Thank you for responding to my question. My apologies for having annoyed you by not using the code tag.
I have the file, and I have done list() and listFiles, but I get the wrong folder. The folder I do get does not even contain my Spring1 project, let alone a resources folder.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules