Web Programing!/JAVA / JSP
[JSP] 이미지파일 다운로드 구현하기
어설픈봉봉이
2011. 9. 22. 00:07
반응형
SMALL
<%@ page contentType="application/octet-stream;charset=euc-kr" %>
<%@ page import="java.io.*"%>
<%
response.setHeader("Content-Type","image/jpg");
String dFileName= "test.jpg";//다운시 지정할 파일명
String filename2 = new String(dFileName.getBytes("8859_1"),"euc-kr"); //한글 파일일 경ㅇ우
String path = "c:/"; //서버의 경로
java.io.File file = new java.io.File(path+"lee.jpg");//서버상의 존재하는 파일명
byte b[] = new byte[(int)file.length()];
System.out.println( "size : " + b.length);
System.out.println( "filename2 : " + filename2);
System.out.println( "path : " + path);
response.setHeader("Content-Disposition", "attachment;filename=" + new String(dFileName.getBytes("euc-kr")) + ";");
if (file.isFile())
{
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
int read = 0;
while ((read = fin.read(b)) != -1){
outs.write(b,0,read);
}
outs.close();
fin.close();
}
%>
반응형