request对象有个获取当前web应用程序路径的方法,直接调用即可,具体忘记了

解决方案 »

  1.   

    你需要传入参:pageContext上下文
      public String getFilePath(String FilePath) {
        String RealPath = pageContext.getServletContext().getRealPath(FilePath);
        return RealPath;
      }
    PaintChartLable p = new PaintChartLable(); 
    p.launchFrame(); 
    ImageWriter writer = new JPGWriter();  
    String realpath=getFilePath(chartName +  "Chart.jpg");
    writer.write(p,new FileOutputStream(realpath)); 
      

  2.   

    主要是在java代码中实现找到webroot路径的
    需要的是classloader,得到的是classes路径
    再转换成你需要的路径就可以。
    经过一个网友指点,在这谢了他
    代码如下:String url = this.getClass().getClassLoader().getResource("").getPath();
    String path = url.replace("\WEB-INF", "");
    Path += "\\images\\";以上朋友说的是在jsp中拿到路径的办法。不过也谢了他们给我一些启发。