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;
            },
    

      

  • 相关阅读:
    VMWare虚拟机非正常关机后无法启动
    curl: (1) Protocol "'https" not supported or disabled in libcurl的解决方法
    spring security入门
    oracle中可以使用drop、delete和truncate三个命令来删除数据库中的表
    com.github.pagehelper:pagehelper:jar:3.4.2-fix.jar
    oracle jdbc驱动 ojdbc14-10.2.0.4.0.jar 网盘下载
    PDF复制SQL语句没有换行符的解决办法
    rpm -qa | grep mysql查询不到MySQL
    新文预览 | IoU-aware Single-stage Object Detector for Accurate Localization
    目标检测 | RetinaNet:Focal Loss for Dense Object Detection
  • 原文地址:https://www.cnblogs.com/cx709452428/p/10676910.html
Copyright © 2011-2022 走看看