개발 등/JSP

다운로드 서블릿 컨텐트 타입 지정하기

darkhorizon 2011. 10. 11. 16:12
728x90
반응형

if(tempFileName.indexOf("pdf") != -1){
      response.setContentType("application/pdf");
}else if(tempFileName.indexOf("hwp") != -1){
      response.setContentType("application/x-hwp");
}else if(tempFileName.indexOf("jpg") != -1){
      response.setContentType("image/jpeg");
}else if(tempFileName.indexOf("gif") != -1){
      response.setContentType("image/gif");
}else{
      response.setContentType("application/octet-stream");
}
if(request.getHeader("User-Agent").toLowerCase().indexOf("firefox") != -1){
      response.setHeader("Content-Disposition", "attachment; filename=\"" +
         new String(tempFileName.getBytes("UTF-8"), "ISO-8859-1") + "\"");

}else{
     response.setHeader("Content-Disposition", "attachment; filename=\"" + 
         URLEncoder.encode(tempFileName,"UTF-8") + "\"");

}
728x90