본문 바로가기

웹개발

[JSP] 한글 파일명 다운로드

TOMCAT6.0 / JAVA 1.6

<%@page import="java.io.FileInputStream"%>

<%@page import="java.io.OutputStream"%>

<%@ page pageEncoding="EUC-KR"%>

<%

response.reset();

String filename = new String("한글테스트.txt".getBytes("euc-kr"),"iso-8859-1");

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

response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");

response.setHeader("content-Transfer-Encoding","binary");

response.setHeader("Pragma","no-cache;");

response.setHeader("Expires","-1");

out.clear();

  out = pageContext.pushBody();

FileInputStream is = new FileInputStream("c:\\한글test.txt");

byte[] data = new byte[900]; // 이건 뭘까?..

OutputStream os = response.getOutputStream();

int len = -1;

while((len = is.read(data)) != -1){

os.write(data,0,len);

}

is.close();

response.getOutputStream().close();

%>