@RequestMapping("download.do")
public void download(HttpServletResponse response, @RequestParam("id")String id) throws Exception {
// id를 이용해 db에서 파일 fullPath 와 ofn 얻어오기
String ofn = service.getOfn(id);
String fullPath = service.getFilePath(id);
File target = new File(fullPath);
byte[] b = new byte[1024 * 1024 * 10];
DataOutputStream dos = new DataOutputStream(new FileOutputStream(target));
response.reset();
response.setContentType("application/octet-stream");
String fileName = new String(ofn.getBytes("utf8"), "8859_1");
response.setHeader("Content-Disposition", "attatchment; filename = " + fileName);
response.setHeader("Content-length", String.valueOf((int)target.length()));
FileInputStream fis = new FileInputStream(target);
ServletOutputStream sos = response.getOutputStream();
int num;
while((num = fis.read(b,0,b.length)) != -1) {
sos.write(b,0,num);
}
sos.flush();
sos.close();
fis.close();
}
'JAVA 개발 공부 정보' 카테고리의 다른 글
자바수업-스프링 Chapter06-스프링MVC (0) | 2018.02.22 |
---|---|
자바연습 - Chapter06_1 x+y=결과 (0) | 2018.02.22 |
[개발교육] 자바 jsp 기초 - 8(output.jsp) (0) | 2018.01.15 |
[개발교육] 자바 jsp 기초 - 8(InputHtml) (0) | 2018.01.15 |
[개발교육] 자바 jsp 기초 - 7(스크립트 이벤트 처리) (0) | 2018.01.15 |