System.out.println(  request.getRequestURI() );

解决方案 »

  1.   

    我要得到的是这个webapp的根目录
    不是那个请求路径
    也就是说无论什么时候都应该得到/test而不是访问根目录的文件的时候才能得到/test
      

  2.   

    一个简单的笨方法(太笨别砸我啊。)
    在程序的某个地方添上下面几句:    File theFile = new File("tmp");
        if( !theFile.exists()) theFile.deleteOnExit();
        String name = theFile.getAbsolutePath();
        int len = name.length();
        String thePath = thePath.substring(0,len-3);
     thePath就是路径,包括系统分割符,就是笨了点。
    //好象有可以取得路径的法子,这会忘了。