1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition",
"attachment;filename=rapport.zip");
InputStream in = null;
OutputStream out = null;
try {
URL url = getServlet().getServletContext().getResource(
"rapport.zip");
if(url==null) throw new Exception("rapport.zip not found");
in = url.openStream();
out = response.getOutputStream();
byte[] outputByte = new byte[4096];
for(int n = 0;
(n = in.read(outputByte, 0, 4096)) >0;
out.write(outputByte, 0, n));
out.flush();
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
try {if(in!=null) in.close();} catch(Exception ex) {}
try {if(out!=null) out.close();} catch(Exception ex) {}
} |
Partager