81,122
社区成员




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());
}
<jsp-config>
<jsp-property-group>
<description>
Special property group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>