@RequestMapping(value =ActionUrlManage.ExportG1030Action, method = RequestMethod.POST)
public void exportExcelG1030Controller(HttpServletRequest request,HttpServletResponse response, 
ModelMap modelMap) throws Exception {  
 List<String> list = new ArrayList<String>();  
     list.add("1");  //test
     list.add("2");  
     HSSFWorkbook wb = gi.getUserExcel(list);  
     response.setContentType("application/vnd.ms-excel");    
     response.setHeader("Content-disposition", "attachment;filename=student.xls"); 
     OutputStream ouputStream = response.getOutputStream();//new FileOutputStream(new File(path+"a.xls"));
     wb.write(ouputStream);  
     ouputStream.flush();  
     ouputStream.close();}
点按钮不弹出下载对话框是为毛呢!  谢谢!

解决方案 »

  1.   

    换个游览器试一试呢!你试一试这个
     FileInputStream input=new FileInputStream(file);
      OutputStream output=response.getOutputStream();
     
      //有的游览器对下面的可能不支持,就可以重新设置一个头response.setHeader("content-type","application/x-gzip");
      //encode方法只对部分IE有效,想要对火狐等游览器有效,可以将filename转成ISO8859-1的编码之后在打给游览器
      response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(realFilename,"UTF-8"));
      byte[] b=new byte[1024];
      int len=0;
      while((len=input.read(b))!=-1){
       output.write(b,0,len);
      }
      input.close();
      output.close();
      

  2.   

    前后台都用get请求方式
      

  3.   

    我想知道你是用什么方式提交的,你是不是用ajax提交的,ajax是没法弹出的,
    要改成wondow.location
      

  4.   

    这里有个例子你可以参照看看;我感觉,下载首先要有下载源吧,没有下载源如何能够下载;所以你点击下载调用相应servlet时,要生成一个下载源,然后复制进输出的文件
    String filename=request.getParameter("filename");
    response.setContentType("application/vnd.ms-excel"); 
    response.setHeader("Content-Disposition" ,"inline; filename="+filename);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in=null;
    ServletOutputStream outexcel = null;
    HSSFWorkbook wb = new HSSFWorkbook();
    Complete comp=new Complete();

    DutyTable dutytable=new DutyTable();
    List <DutyTable> DTlist=new ArrayList<DutyTable>();
    dutytable.setDate("9月16日");
    dutytable.setRes("");
    dutytable.setSign(" ");
    dutytable.setWatcher("往哪");
    dutytable.setWeekDay("星期一");
    DTlist.add(dutytable);

    int rownum = 0;
    wb=comp.creat(rownum,wb,DTlist);
    wb.write(out);
    out.flush();
    byte[] aa = out.toByteArray();
    in = new ByteArrayInputStream(aa, 0, aa.length);
    outexcel=response.getOutputStream();
    outexcel.flush();
    int aRead = 0;  
            while ((aRead = in.read()) != -1 & in != null) {  
                outexcel.write(aRead);  
             }  
    in.close();
    out.close();
    outexcel.close();

      

  5.   

    哥们,界面发个看看。前台用什么做的?jsp,ftl,ext?
      

  6.   

    http://blog.csdn.net/zhaoxiaoyueyue/article/details/39343853 完整的例子,懒得码字,自己去看看吧
      

  7.   


    用的是ext,这样可以么tbar:[ 
                         {text:'导出',iconCls:'del',handler:function(){
                          var Form = Ext.create('Ext.form.Panel',{
                          url: './export'+record.raw.name+'.action', 
                          onSubmit:Ext.emptyFn,//非AJAX提交
                          submit:function()
                          {
                          this.getForm().getEl().dom.submit();   
                          }
                                                 
                          });
                          Form.getForm().submit();                       
                                              }
                         },
      

  8.   

    你这肯定是不行的啊, 你用数据的输出流生成一个 Panel , panel 无法自适这个数据流的, 如果你想要下载的话, 换一种方式接受下来, 比如说放到 一个 iframe 里面, 用这个 iframe 接受 url 生成下载流// 如果页面中没有用于下载iframe,增加iframe到页面中
    if ($('#downloadcsv').length <= 0)
    $('body')
    .append("<iframe id=\"downloadcsv\" style=\"display:none\"></iframe>");
    $('#downloadcsv').attr('src', url);
      

  9.   


    用的是ext,这样可以么tbar:[ 
                         {text:'导出',iconCls:'del',handler:function(){
                          var Form = Ext.create('Ext.form.Panel',{
                          url: './export'+record.raw.name+'.action', 
                          onSubmit:Ext.emptyFn,//非AJAX提交
                          submit:function()
                          {
                          this.getForm().getEl().dom.submit();   
                          }
                                                 
                          });
                          Form.getForm().submit();                       
                                              }
                         },
    哥们,我用ext做了一个,前台面板是这么设计的,供你参考下
    var fpFileUpload=new Ext.FormPanel({
                id:'fpFileUpload',
                frame:true,
                fileUpload:true,
                //url:'Default.aspx',
                items:[
                    {
                        xtype:'textfield',
                        allowBlank:false,
                        fieldLabel:'选择文件',
                        inputType:'file',
                        name:'excelFile'//后台封装名为excelFile属性
                    }
                ],
                buttonAlign:'center',
                buttons:[
                    {
                        text:'上传',
                        handler:function(){
                            if(fpFileUpload.form.isValid()){
                                fpFileUpload.form.submit({
                                    url:'importFromExcel4Wage.action',//这里的名称需要修改,具体和陈巍讨论。
                                    method:'post',
                                    waitTitle:'请等待',
                                    waitMsg:'文件上传中...',
                                    success: function(form,action) {
                                        Ext.Msg.alert("系统提示", action.result.msg);
                                         winFielUpload.hide();
     //grid.store.load();
                                    },
                                    failure: function(form,action) {
                                        Ext.Msg.alert("系统提示",action.result.msg);
                                        winFielUpload.hide();
                                    }
                                });
                            }else{
                                Ext.Msg.alert("系统提示","请选择文件后再上传!");
                            }
                        }
                    },
                    {
                        text:'取消',
                        handler:function(){
                            winFielUpload.hide();
                        }
                    }
                ]
            });
      

  10.   

    导出excel文件,可以用pageoffice插件实现,很简单就可以实现的
      

  11.   

    问题解决,感谢各位大佬
    解决方式如下:使用GET提交,不用ajax提交,使用window.href提交。