<%
OutputStream outStream = null;
FileInputStream fileStream = null;
try {
//주소와 파일이름 가져오기
String displayName = request.getParameter("fileName");
String filePath = request.getParameter("filePath");
response.setContentType("application/x-msdownload");
//위 세팅으로 안될 경우에 사용.
//response.setContentType("application/octet-stream");
//Content-Disposition 세팅하기위해 file 이름을 변환한다.
String Env = (String)System.getProperty("Env");
// // 한글 파일 변환
//filePath= new String(filePath.getBytes("KSC5601")); 혹은
filePath= new String(filePath.getBytes("8859_1"), "MS949");
// 인코딩이 필요할 경우
//displayName = java.net.URLEncoder.encode(displayName,"UTF-8");
//Content-Disposition 헤더에 파일 이름 세팅.
response.setHeader("Content-Disposition", "attachment;filename=" + displayName + ";");
//위 세팅으로 안될 경우에 사용.
//response.setHeader("Content-Disposition","attachment;fileName=\""+displayName+"\";");
// 폴더에 있는 파일 가져오기 위해 다른 방법으로 변환
File file = new File(filePath);
byte[] byteStream = new byte[(int)file.length()];
fileStream = new FileInputStream(file);
int i=0;
int j=0;
while( (i=fileStream.read()) != -1 ){
byteStream[j] = (byte)i;
j++;
}
out.clear(); //out--> jsp자체 객체
out=pageContext.pushBody(); //out--> jsp자체 객체
outStream = response.getOutputStream();
outStream.write(byteStream);
}catch(Exception e) {
System.out.println(e);
}finally {
if(fileStream != null) fileStream.close();
if(outStream != null) outStream.close();
}
%>
'프로그래밍 > java' 카테고리의 다른 글
이클립스 workspace 변경 파일 (0) | 2012.10.14 |
---|---|
이클립스 시작시 loading workbench eclipse 멈출때 (0) | 2012.10.14 |
[이클립스] 에디터 text 인코딩변경.. (0) | 2012.10.08 |
스프링 applicationContext.xml DB connect 접속 설정 예 (0) | 2012.10.08 |
jsp 페이지에서 보안서버 http 로 접근시 --> https 로 이동 (0) | 2012.09.12 |
org.apache.commons.fileupload 파일 업로드 (0) | 2012.08.16 |
org.apache.commons.mail 메일 보내기 (0) | 2012.08.16 |
eclipse.ini (0) | 2012.01.13 |
JRebel 연동하기 (0) | 2011.10.28 |
자바형변환 (0) | 2011.10.24 |
댓글