1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| private void doDownload( File f, HttpServletResponse resp,String filename, String original_filename,boolean forceDownload )
throws Exception
{
int length = 0;
resp.setCharacterEncoding("ISO-8859-1");
ServletContext context = getServletConfig().getServletContext();
String mimetype = context.getMimeType( filename );
if (mimetype==null) mimetype="application/octet-stream";
resp.setContentLength((int)f.length());
if (forceDownload)
{
resp.setContentType("application/force-download");
resp.setHeader("Content-Disposition","attachement; filename=\""+original_filename+"\"");
}
else
{
resp.setContentType(mimetype);
resp.setHeader("Content-Disposition","attachement; filename=\""+original_filename+"\"");
}
DataInputStream in = new DataInputStream(new FileInputStream(f));
PrintWriter op = resp.getWriter();
try {
int bit = in.read();
while ((bit) >= 0) {
op.write(bit);
bit = in.read();
}
}catch (Exception e) {
}
in.close();
op.flush();
op.close();
}
} |
Partager