|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.FileInputStream; |
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.InputStream; |
|
|
import java.io.OutputStream; |
|
|
import java.io.OutputStream; |
|
|
import java.net.URLEncoder; |
|
|
import java.net.URLEncoder; |
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
//清空缓存 |
|
|
//清空缓存 |
|
|
response.reset(); |
|
|
response.reset(); |
|
|
// 定义浏览器响应表头,并定义下载名 |
|
|
// 定义浏览器响应表头,并定义下载名 |
|
|
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8"); |
|
|
|
|
|
|
|
|
//String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8"); |
|
|
|
|
|
String urlFileName =new String(("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc").getBytes(), StandardCharsets.ISO_8859_1); |
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName); |
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName); |
|
|
response.setCharacterEncoding("utf-8"); |
|
|
response.setCharacterEncoding("utf-8"); |
|
|
//定义下载的类型 |
|
|
//定义下载的类型 |
|
|
response.setContentType("application/msword;charset=gbk"); |
|
|
|
|
|
|
|
|
response.setContentType("application/msword;charset=utf-8"); |
|
|
OutputStream out; |
|
|
OutputStream out; |
|
|
File files = new File(filePath); |
|
|
File files = new File(filePath); |
|
|
|
|
|
|
|
|
log.info("读出的文件文件地址为:{}",filePath); |
|
|
log.info("读出的文件文件地址为:{}",filePath); |
|
|
FileInputStream inputStream = new FileInputStream(files); |
|
|
|
|
|
|
|
|
InputStream inputStream = this.getClass().getResourceAsStream(filePath); |
|
|
|
|
|
//FileInputStream inputStream = //new FileInputStream(files); |
|
|
//3.通过response获取ServletOutputStream对象(out) |
|
|
//3.通过response获取ServletOutputStream对象(out) |
|
|
out = response.getOutputStream(); |
|
|
out = response.getOutputStream(); |
|
|
int b = 0; |
|
|
int b = 0; |