sitelink1 http://blog.naver.com/shreds?Redirect=Log&logNo=89747030 
sitelink2 http://www.iana.org/assignments/media-types/text/index.html 
sitelink3  
sitelink4  
sitelink5  
sitelink6  

1. setContentType 메서드

public void setContentType(java.lang.String type)
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called.

This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type header is used.

Parameters:
type - a String specifying the MIME type of the content


2. MIME Type

text/html

audio/mpeg
image/bmp
image/jpeg
application/pdf
application/java
application/jar
application/x-zip
application/msword
application/msaccess
application/vnd.ms-excel
application/vnd.ms-powerpoint
application/octet-stream


마지막에 굵게 표기되어 있는 octet-stream 이라는 놈은 이름 그대로 8비트 바이너리 배열을 의미하며 http나 이메일상에서 application 형식이 지정되지 않았거나 형식을 모를때 사용합니다. 결국 브라우저는 octet-stream 으로 MIME 타입이 지정된 경우 단지 바이너리 데이터로서 다운로드만 가능하게 처리하게 됩니다.


※ setContentType 메소드로 contentType을 지정해 놓고 출력 스트림을 바꾸는 것은 물건을 줬다 뺐는 행위입니다.
즉 setContentType 메소드가 제일 먼저 호출되고 getOutputStream과 같은 출력 스트림 메소드가 사용되어져야 합니다

response.setContentType("application/octet-stream");

//... 중간생략
//... 중간생략

byte[] bytestream = new byte[(int)file.length()];
filestream = new FileInputStream(file);

int i = 0, j = 0;
while((i = filestream.read()) != -1) {
   bytestream[j] = (byte)i;
   j++;
}
outStream = response.getOutputStream();
outStream.write(bytestream);


번호 제목 글쓴이 날짜 조회 수
223 String to InputSource 황제낙엽 2012.12.03 601
222 Class.getResource() vs. ClassLoader.getResource()/getResources() 황제낙엽 2012.06.24 466
221 Jar파일에 포함된 리소스 접근하는 방법(How to read a resource from a JAR file ) file 황제낙엽 2012.06.24 475
220 Java에서 URL 다루기 file 황제낙엽 2012.06.24 396
» HttpServletResponse.setContentType(java.lang.String type) 과 MIME 타입 황제낙엽 2012.04.20 509
218 code, codebase 속성과 applet object 동적 생성 file 황제낙엽 2012.04.17 451
217 한글 파일명 깨짐으로 살펴본 다국어 처리 문제 (UTF-8) 황제낙엽 2012.03.22 10403
216 BufferedReader.readLine() hangs 황제낙엽 2012.02.23 809
215 OS 쉘 명령어(shell script) 실행하기 [ProcessBuilder, Runtime.getRuntime().exec()] 황제낙엽 2012.02.22 923
214 PreProcess 실행 (전처리기 만들기) file 황제낙엽 2012.01.04 478
213 javax.script와 타입변환 황제낙엽 2012.01.03 430
212 Scripting within Java 황제낙엽 2012.01.03 393
211 Hex string <-> String object 황제낙엽 2011.11.29 611
210 An alternative to the deep copy technique file 황제낙엽 2011.07.27 570
209 <jsp:include>, include지시자 file 황제낙엽 2011.07.24 438
208 <jsp:include> 액션태그 황제낙엽 2011.07.24 403
207 volatile 에 대한 단상(斷想) 황제낙엽 2011.06.22 425
206 Object element 의 onerror 이벤트 황제낙엽 2011.04.21 295
205 Java 2D Graphics - Reference link 황제낙엽 2011.04.11 459
204 deployJava.js를 이용한 JRE 자동설치 및 Applet 디플로이 file 황제낙엽 2011.04.04 943