getRealPath是ServletContext的方法,保证在写文件之前要创建excel目录String contextPath = xxxServlet.getServletContext().getRealPath("/WEB-INF/excel");
File fdir = new File(contextPath);
if (!fdir.exists()) {
if (fdir.mkdir() == false) {
System.out.println("dir create fail");
}
}
FileOutputStream fileOut = new FileOutputStream(contextPath+"/"+filename+"showExcel.xls");

解决方案 »

  1.   

    不行,不管是用HttpServletRequest的getRealPath或者是ServletContext的getRealPath都会出现错误!
      

  2.   

    我从JSP页面传递给了它一个REQUEST,现在可以了。但是还是只能在工程所在的目录里,到不了我虚拟的哪个路径所在的文件夹
      

  3.   

    docBase="d:\sczj是不是\转义了?
    d:/sczj
      

  4.   

    path="f:\\excel\\"+filename+"showExcel.xls";
      

  5.   

    不能用绝对路径的,最后要移植到LINUX上的!
      

  6.   

    public static String path="excel/"+filename+"showExcel.xls";这和你设定<Context path="/sczj" docBase="d:\sczj" debug="0"
                     reloadable="true" crossContext="true" />
    是没有关系的。
    path="a.xls"
    那么生成的文件就是放在bin(版本不同存放文字好象也不一样的)
    如果你要用固定文字的(相对路径的)
    path="/root/a.xls"
    那么root文件夹是在与wen-inf同级的目录下的