好像是用 request 的 getPathTranslated() 方法吧

解决方案 »

  1.   

    错了,应该是 getRealPath(String)
    不过这个方法是 Deprecated 的,我再找找看其它方法。
      

  2.   

    ServletContext 有 getRealPath(String) 方法
    HttpServlet 有 getServletContext() 方法可以取得 ServletContext 对象
      

  3.   

    public URL getResource(String name)
    Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class. 
    This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource. 
    Parameters:
    name - name of the desired resource 
    Returns:
    a java.net.URL object.
    Since:
    JDK1.1 
    See Also:
    ClassLoader
      

  4.   

    java aplication: 
    System.getProperty("user.dir");//获得当前执行目录
    Test t = new Test();
    t.getClass().getResource("/"); //或得当前程序所在目录jsp:
    application.getRealPath("/");//当前文件所在目录
    System.getProperty("user.dir");//获得当前执行目录
      

  5.   

    <jsp:application.getContextPath(".") />