2010-07-22 57 views

回答

1

使用servletContext.getRealPath("/someuidir-in-your-webapp/somejspdir")获取该jsp目录的绝对路径,然后使用java.io.File和java.io.FileFilter(过滤目录)。这里的javadoc for getRealPath

添加一些代码(你可以把它放在你的jsp中)。请注意,这只是一个让你开始如何做的例子。这可能需要一些imporovement(在设计方面)

<% 
    File jspDir = new File(application.getRealPath("/WebContent")); 
    File[] list = jspDir.listFiles(new FileFilter() { 
     public boolean accept(File path) { 
      return path.isDirectory(); 
     } 
    }); 

    for(File f : list) { 
    out.write("<p>" + "</p>"); // replace this with whatever way you 
           // want to populate 
    } 
    %> 
+0

我设法使用<%= request.getRealPath(“/的WebContent”)%> 我怎么使用目录过滤,以获得真实路径是现在?对不起,但我是JSP的新手! – GPX 2010-07-22 05:50:18

+0

感谢您的回答!我想到了!好极了!! – GPX 2010-07-22 10:13:30