解决方案 »

  1.   

    导出后文件打开失败和提示已经被打开,是因为你程序的输出流没有关闭。你本地程序往web程序迁移,需要将文件流写入response输出流中,然后在浏览器中下载啊。
      

  2.   

    移植过去导出的数据和原来程序导出的数据是否一致,还有文件打开了要关闭。
    要下载文件,必须把文件数据暴露给用户,比如把导出的文件放到web目录下通过地址直接下载,或参考楼上的方法
      

  3.   


    public class ExportUtil {
    private Configuration configuration = null;       
        public ExportUtil(){  
            configuration = new Configuration();  
            configuration.setDefaultEncoding("UTF-8");  
        }
                public void createApplyInfoExcel(String modelPath,String modelName,String fileName,Map dataMap) throws UnsupportedEncodingException{  
            Map<String,Object> excelMap=new HashMap<String,Object>();  
            getData(excelMap,dataMap);  
            configuration.setClassForTemplateLoading(this.getClass(),modelPath);  //FTL文件所存在的位置  
            Template t=null;  
            try {  
                t = configuration.getTemplate(modelName); //文件名  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
            File outFile = new File("C:/"+fileName+".xls");  //生成文件的路径         //String path=System.getProperty("user.dir");      //放web程序可用该路径
            //File outFile=new File(path+fileName+".xls");        
            Writer out = null;  
            try {  
                out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));  
            } catch (FileNotFoundException e1) {  
                e1.printStackTrace();  
            }  
               
            try {           
                t.process(excelMap, out);  
            } catch (TemplateException e) {  
                e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  }
    至于导出另存
    可以用response.sendRedirect(request.getContextPath()+"/存放路径/"+fileName);