jsp中导出excle,如何自己设置保存路径,我可以在页面上通过input设置文件名,但如何让操作人员选择保存路径。
帮帮忙吧,谢谢了

解决方案 »

  1.   

    jsp  out.println(io);
    自动会有保存提示啊
      

  2.   

    能说的详细点吗?我用jxl完成的excel导出,你们说的自动保存提示如何实现
      

  3.   

    你在点击按钮的时候 进入controller  
    controller可以这样实现
    OutputStream outStream=null;
            try {   
             String tempfileName = new String(filename.getBytes("GBK"),"ISO8859_1");       
             response.setContentType("application/vnd.ms-excel"); 
            response.addHeader("Content-Disposition", "attachment; filename="+tempfileName); 
            //获取系统所在服务器本地路径
            String webPath = request.getSession().getServletContext().getRealPath("/");
            System.out.println(webPath);
            //创建一个存放下载文件的临时目录
            String tempFile = "tempDownLoad";
            File tempDir = new File(webPath + "/" + tempFile);
            if(!tempDir.exists()){
             tempDir.mkdirs();
            }
            outStream = response.getOutputStream();
    //调用services方法  这里是里面的代码  基本思路就是这样的  把xls放到流里去 
    //或者实在不行 你可以先保存到服务器  然后用fileinputstream  读取成io流 
     {
    HSSFWorkbook hssf;
    hssf = BuildXLSHelper.buildXLS(configure, record);
    hssf.write(out);
    }
           outStream.flush();
         outStream.close();
            }catch(Exception e)
            {
             e.printStackTrace();
            }
      

  4.   

    就是现保存到服务器再从服务器下载?如果想通过jxl直接保存到用户桌面则没法自己选择路径
      

  5.   

    7楼代码难道是保存到服务器?
    //获取系统所在服务器本地路径
    String webPath = request.getSession().getServletContext().getRealPath("/");
      

  6.   

    我才入门,不是太懂,7楼的意思是把xls文件放到临时文件夹内然后放到流里下载
      

  7.   

    String webPath = request.getSession().getServletContext().getRealPath("/");
     System.out.println(webPath);
     //创建一个存放下载文件的临时目录
    String tempFile = "tempDownLoad";
     File tempDir = new File(webPath + "/" + tempFile);
     if(!tempDir.exists()){
     tempDir.mkdirs();
     }这段是二选一  就是要么直接hssk.wirte(out);
    要么可以save("零时文件夹");
    返回地址到前台  在超链接下载