location.href 跳转到action后 返回问题-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

location.href 跳转到action后 返回问题

我用location.href转到后台 导出excel,

但当查询出的数据不满足条件时,我不导出excel,不进行操作,页面就会变空白,

Long count = custMtTranService.getCountByParams(params);
            if(count<=50000){
                List<Tran> trans = custMtTranService.getCustMtTranByParams(params);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                List<String[]> headNames = new ArrayList<String[]>();
                headNames.add(new String[] { "客户号", "客户名称","订单编号","MT4账户","交易品种","报价小数位数","开仓时间","开仓价格","交易量","止损价位","止盈价位",
                        "平仓时间","平仓价格","外佣","代理商佣金","盈利金额","订单备注"});
                List<String[]> fieldNames = new ArrayList<String[]>();
                fieldNames.add(new String[] { "custNo", "custName","orderId","login","symbol","digits","openTime","openPrice","volume","sl","tp",
                        "closeTime","closePrice","commission","commissionAgent","profit","comments"});
                LinkedHashMap<String,List> map1=new LinkedHashMap<String,List>();
                map1.put("交易数据", trans);
                ExportSetInfo setInfo = new ExportSetInfo();
                setInfo.setObjsMap(map1);
                setInfo.setFieldNames(fieldNames);
                setInfo.setTitles(new String[] { "交易信息"  });
                setInfo.setHeadNames(headNames);
                setInfo.setOut(baos);
                // 将需要导出的数据输出到baos
                ExcelUtil.export2Excel(setInfo);
                // 生成提示信息,
                response.setContentType("application/vnd.ms-excel");
                String codedFileName = null;
                OutputStream fOut = null;
                // 进行转码,使其支持中文文件名
                codedFileName = java.net.URLEncoder.encode("交易信息", "UTF-8");
                response.setHeader("content-disposition", "attachment;filename="
                        + codedFileName + ".xls");
                fOut = response.getOutputStream();
                baos.writeTo(fOut);
                fOut.flush();
                fOut.close();
            }else{
                    //数据过多,不能导出
            }

展开
收起
a123456678 2016-03-18 14:40:20 2220 0
1 条回答
写回答
取消 提交回答
  • 方法有很多,我说一个。

    1.在页面添加一个hide的标签,用于获取后台状态数据

    2.后台成功就把标签值置1,失败置0

    3.页面的

    (或者是JQ的document.ready())中添加JS判断hide标签的值,如果是0就alert('数据过多不能导出')
    2019-07-17 19:06:41
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新
相关电子书
更多
AutoAlerts-From Data to Action
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载