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

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

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