java里http服务器如何将文件制成一个下载路径
/
文件下载
/
@RequestMapping("/downloadfile")
public void offLineResponseActiveFile(String resStr, HttpServletResponse response) {
PrintWriter pw = null;
StringBuffer sb = new StringBuffer();
try {
String fileName = "文件名";
responsesetCharacterEncoding("UTF-8");
responsesetContentType("application/x-msdownload");
responseaddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
responseaddHeader("charset", "utf-8");
responseaddHeader("Pragma", "no-cache");
responsesetHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"; filename=utf-8''" + fileName );
sbappend(resStr);
pw = responsegetWriter();
pwwrite(sbtoString());
pwclose();
responseflushBuffer();
} catch (IOException e) {
loggerinfo("下载文件出错");
eprintStackTrace();
if (pw != null) {
pwclose();
}
} finally {
if (pw != null) {
pwclose();
}
}
}
resStr 字段传写入文件里的内容
0条评论