ServletContext sc = getServletContext();
//取得webroot的实际位置
String filePath = sc.getRealPath(“/”);
假设返回值是:D:\..\..\webroot
filePath = filePath + "WEB-INF"new File(filePath+"catalog.xml");

解决方案 »

  1.   

    照你的写法,无法编译,ServletContext sc = getServletContext();
    eclipse3.1.2
      

  2.   

    我看到你要写到WEB-INF下,我假设你是的Web应用
    关于如何获得ServletContext:
    1,Servlet内
    在Servlet内调用getServletContext()
    或session.getServletContext()
    2,Jsp内
    application对象就是ServletContext
      

  3.   

    jsp我不懂.
    有没有不需要用jsp的方法,其实很简单,就是需要一个相对的路径."../a/a.xml"貌似这样的.我主要是要写一个xml文件到一个文件夹里面,然后去读取.
    你说的Servlet我不懂.
      

  4.   

    Properties p = System.getProperties();
    String path = p.getProperty("user.dir");
    path + "/a/a.xml"
    你看能用吗?