<%@ page contentType="text/html; charset=euc-kr" pageEncoding="EUC-KR"
import="java.io.*"%>
<%
out.clear();
out = pageContext.pushBody();
String fileName = request.getParameter("file_name");
String filePath = this.getServletContext().getRealPath("/upload/");
String full_path = filePath + "\\" + fileName;
//response.setContentType("application/x-msdownload");
response.setHeader("Content-Type", "aapplication/x-msdownload");
response.setHeader("Content-Disposition", "attachment;filename="+ fileName + ";");
//String convName1 = java.net.URLEncoder.encode(new String(fileName.getBytes("8859_1"), "euc-kr"),"UTF-8");
String convName1 = new String(fileName.getBytes("8859_1"), "euc-kr");
// System.out.println(filePath);//test 용
// System.out.println(convName1);
File file = new File(filePath + "\\" + convName1);
if (fileName == null) {
System.out.println("");
}
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file)); // 인풋객체생성
BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
byte b[] = new byte[(int) file.length()];
if (file.length() > 0 && file.isFile()){// 0byte이상이고, 해당 파일이 존재할 경우
int read = 0;
try {
while ((read = fin.read(b)) != -1) {
outs.write(b, 0, read);
}
outs.flush();// 본인이 추가한 코딩부분.
}
catch (Exception e) {
System.out.println("download error : " + e.getMessage());
}
finally {
if (outs != null)
outs.close();
if (fin != null)
fin.close();
}
}
%>
'IT 전용글 > JSP' 카테고리의 다른 글
JSTL , CustomTag , 국제화 (0) | 2009.01.29 |
---|---|
JSP 요청 헤더 값 구하는 방법.. (0) | 2009.01.28 |
우편번호 파일. / 테이블 (0) | 2009.01.13 |
Jsp Jar 파일 모음. (0) | 2009.01.13 |
Excel Reader (0) | 2009.01.13 |