티스토리 뷰
아래의 형식으로 그대로 붙여넣기를 하면 된다.
출처는 naver 지식인.
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.io.*"%>
<%
OutputStream outStream = null;
FileInputStream fileStream = null;
try {
//주소와 파일이름 가져오기
String fileName = request.getParameter("fileName");
String filePath = "C:/tomcat6/webapps/ROOT/upload/";
//또는 아래 사용
//String filePath = request.getRealPath("/")+"uploadFile/";
//System.out.println(filePath);
//응답 헤더의 Content-Type을 세팅한다.
response.setContentType("application/x-msdownload");
//위 세팅으로 안될 경우에 사용.
//response.setContentType("application/octet-stream");
//Content-Disposition 세팅하기위해 file 이름을 변환한다.
String convName1 =
java.net.URLEncoder.encode(fileName,"UTF-8");
//Content-Disposition 헤더에 파일 이름 세팅.
response.setHeader("Content-Disposition", "attachment;filename=" + convName1 + ";");
//위 세팅으로 안될 경우에 사용.
//response.setHeader("Content-Disposition","attachment;fileName=\""+Convfilename+"\";");
// 폴더에 있는 파일 가져오기 위해 다른 방법으로 변환
String convName2 = fileName;
File file = new File(filePath+convName2);
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();
}
%>
- Total
- Today
- Yesterday
- 테라로사
- 부천역
- 담양 죽녹원
- pdf ms워드 변환
- 임자도
- 정동지
- java api
- 대관령양떼목장
- 밀리세컨드
- 이클립스
- 제주도여행
- oracle
- 토드
- PPTX
- 인천여행
- ora-01940
- jdk
- 가평팬션
- 맛집
- 보성녹차밭
- 파주여행
- 오라클
- 인스타그램
- 산외한우마을
- 덤프
- 인천
- 가평여행
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |