2010-07-22 56 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