Commit 2b915223 authored by 周昊's avatar 周昊

1、修改pc端导出风险告知卡图片

parent 1e2af8dd
......@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
......@@ -91,33 +92,27 @@ public class WordUtil {
* @throws IOException
*/
public static void responseDownloadFile(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) throws IOException {
// 读到流中
InputStream inStream = new FileInputStream(filePath + fileName);
String agent = request.getHeader("User-Agent").toUpperCase();
String encodedfileName = "";
// IE
if (agent.indexOf("MSIE") != -1 || agent.indexOf("TRIDENT") != -1) {
encodedfileName = URLEncoder.encode(fileName, "utf-8");
// 谷歌或火狐
} else if (agent.indexOf("CHROME") != -1 || agent.indexOf("FIREFOX") != -1) {
encodedfileName = new String(fileName.getBytes("utf-8"), "ISO8859-1");
} else {
encodedfileName = new String(fileName.getBytes("utf-8"), "ISO8859-1");
}
// 设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
// 循环取出流中的数据
byte[] b = new byte[100];
int len;
while ((len = inStream.read(b)) > 0) {
response.getOutputStream().write(b, 0, len);
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
// 设置浏览器以下载的方式处理该文件名
response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
File file = new File(filePath + "/" + fileName );
try (InputStream fin = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream()) {
// 缓冲区
byte[] buffer = new byte[512];
int bytesToRead;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// 删除临时文件
file.delete();
}
inStream.close();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment