Announcement Announcement Module
Collapse
No announcement yet.
getting directory listing from Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #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...

    Comment


    • #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.

      Comment

      Working...
      X