java WEB导出文件后端,前端代码

1. 前端请求不能是原来的

$.ajax请求; 

    window.location.href = downScheduleInfoUrl+"?"+参数

 Java后台导出Excel表,没有出现下载提示问题解决
   PS:将访问方式ajax改成  location.href = url就行了。
   https://blog.csdn.net/a1029573879a/article/details/83419529

 

2. 火狐乱码导出: 设置

https://blog.csdn.net/bylhjcsmmd/article/details/78284736
|----导出 

在导出的 文件名后边加 filename*=utf-8'zh_cn'"

3. 后台导出代码

	title = java.net.URLDecoder.decode(title, "UTF-8");
		InvoiceInfoBP invoiceInfoBP = new InvoiceInfoBP();
		File file = invoiceInfoBP.downScheduleInfo(invoiceId, tripinfoid, title);
		try {
			Response response = Response.current();
			response.reset();
			response.contentType = "application/msexcel;charset=utf-8";
			response.setHeader("Content-disposition",	"attachment;filename*=utf-8'zh_cn'"+java.net.URLEncoder.encode(java.net.URLDecoder.decode(title.replace("(", "(").replace(")", ")"), "utf-8")+ ".pdf", "UTF-8"));
			if(file!=null){
				FileInputStream input=new FileInputStream(file);
				byte[] bytes=new byte[1024];
				while(input.read(bytes)!=-1){
					response.out.write(bytes);
				}
				if(input!=null){
					input.close();
				}
			}
		} catch (Exception e) {
		
		}

 

 

4. 根据不同浏览器设置不同的编码: 

 

boolean isMSIE = (agent != null && agent.indexOf("MSIE") != -1);// != -1 IE浏览器乱码问题
			if (isMSIE) {
				finafileName = java.net.URLEncoder.encode(fileName, "UTF-8");
			} else {
				finafileName = new String(StringUtil.downloadNameCheck(fileName).getBytes(), "ISO8859_1");
			}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值