文件下载另存为

前台 :

function  downFile(){

var form = document.createElement("form");
                        document.body.appendChild(form);
                        
                        var IdInput = document.createElement("input");
                        
                        IdInput.type = "hidden"; //输入框类型
                        
                        form.appendChild(IdInput);
                        
                        IdInput.value =params.dnTransFormId; //传入参数
                        
                        
                        IdInput.name = "dnTransFormId"; //输入框名称
                        
                        form.action = "../transForm/downFile";  //下载路径
                        form.submit();

}

 

controller

def downFile(){
        try{
            println "++_+_+_+_+"+params
          //name 文件名

   //data 文件字节流
            def out = response.getOutputStream()
               response.reset();
               response.setContentType("application/octet-stream");
               response.setContentType("application/OCTET-STREAM;charset=UTF-8");
               response.setHeader("Content-disposition", "attachment;filename=" + name)
               response.setContentType("text/plain");
               out.write(data);
            jsonSuccess()
        }
        catch (e) {
            e.printStackTrace()
            jsonError(e)
        }
    }

 

如有类同,亲见谅

 

posted @ 2018-08-08 15:45  易行舟  阅读(749)  评论(0编辑  收藏  举报