81,092
社区成员
发帖
与我相关
我的任务
分享
private void sendFileByTomcat(UploadFile uf, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
File file = calculateRealPath(uf, false);
if(!file.exists() || !file.isFile()){
return;
}
String encoding = response.getCharacterEncoding();
request.setAttribute("org.apache.tomcat.sendfile.filename", file.getAbsolutePath());
request.setAttribute("org.apache.tomcat.sendfile.start", 0L);
request.setAttribute("org.apache.tomcat.sendfile.end", file.length());
response.setHeader("Content-Disposition", "filename=\"" + toPathEncoding(encoding, uf.getFileName() + uf.getType().getSuffix()+"\""));
response.setContentLength((int) file.length());
response.setContentType(uf.getType().getContentType());
}