zoukankan      html  css  js  c++  java
  • IE浏览器下载后台返回的Excel文件,报错400

    问题描述(见下图):

     问题分析:

    400是后端没有接收到请求
    原因是后端高版本的tomcat不会自动对字符串进行转义
    所以,前端把参数值进行转义,即encodeURI(string)

    问题处理前代码(传参数用一个字符串传递):

            exportExcel(){
                // 导出文件list的内容。
                let uu=$.getCookie('prefixUrl');
                let url=`${uu}/salesReport/exportPublicToExcel`;
                let cookie=$.getCookie('sessionId');
                // let cookie=encodeURI($.getCookie('sessionId'));
                let info='';  //这里是查询条件。
                info=`"createYear":"${this.createYear}","createWeek":"${this.createWeek}"`;
                //type===3即客户拜访情况时,查看的是月
                let type = this.typeListVal
                if(type === 3){
                    info=`"createYear":"${this.createYear}","createMonth":"${this.createMonth}"`;
                }
                // info = encodeURI(info)
                url=`${url}?type=${type}&sessionId=${cookie}&searchParams=${info}`;
                // window.location.href=url;
                // console.log(url)
                window.open(url);
            },
    

    问题处理后代码:

            exportExcel(){
                // 导出文件list的内容。
                let uu=$.getCookie('prefixUrl');
                let url=`${uu}/salesReport/exportPublicToExcel`;
                let cookie=$.getCookie('sessionId');
                // let cookie=encodeURI($.getCookie('sessionId'));
                let info='';  //这里是查询条件。
                info=`"createYear":"${this.createYear}","createWeek":"${this.createWeek}"`;
                //type===3即客户拜访情况时,查看的是月
                let type = this.typeListVal
                if(type === 3){
                    info=`"createYear":"${this.createYear}","createMonth":"${this.createMonth}"`;
                }
                info = encodeURI(info)
                url=`${url}?type=${type}&sessionId=${cookie}&searchParams=${info}`;
                // window.location.href=url;
                // console.log(url)
                window.open(url);
            },
    

      

    将参数处理一下,就可以正常下载了

    补充说明:也可以采用二进制流下载方式处理,可查看前面分享的文章

        还可以直接下面这样,传参方式改一下,所有参数都用&来拼接(需要后台配合)

            exportExcel(){
                // 导出文件list的内容。
                let vm = this;
                let goRealTime,returnRealTime;
                if(vm.goRealTime){
                    goRealTime=new Date(vm.goRealTime).getTime();
                }else{
                   goRealTime = ''; 
                }
                if(vm.returnRealTime){
                    returnRealTime=new Date(vm.returnRealTime).getTime();
                    returnRealTime = returnRealTime + 3600*24*1000;
                }else{
                    returnRealTime = '';
                }
                let uu=$.getCookie('prefixUrl');
                let sessionId=$.getCookie('sessionId');
                // info=`"billType":"${this.billType}","startTime":"${stratT}","endTime":"${entT}","billCode":"${this.orderNumber}","departmentName":"${this.departmentName}","ownerName":"${this.applyUserName}"`;
                // url=`${url}?type=${type}&sessionId=${cookie}&searchParams=${info}`;
                let url=`${uu}/useVehicleApply/exportToExcel?sessionId=${sessionId}&orderNumber=${vm.orderNumber}&departmentName=${vm.departmentName}&applyUserName=${vm.applyUserName}&goRealTime=${goRealTime}&returnRealTime=${returnRealTime}&licensePlate=${vm.licensePlate}&applyStatus=${vm.applyStatus}&useCarType=0` ;
                // console.log(url);
                window.location.href=url;
            },
    

      

  • 相关阅读:
    【案例】ORA-02298
    ORA-01578: ORACLE 数据块损坏 (文件号 10, 块号 57896)ORA-01110: 数据文件 10: '/data/oradata/prod35.dbf'
    mysql主从架构,IO、SQL线程运行为YES,从库没有同步数据
    MySQL5.7.21报错:[Err] 1055
    ORACLE数据库黑/白名单
    Mongodb日常管理
    hive Hbase sql
    hive DDL操作
    hive 分桶及抽样调查
    hive 排序
  • 原文地址:https://www.cnblogs.com/cx709452428/p/10676910.html
Copyright © 2011-2022 走看看