java 다운로드 한글 깨짐
파일 다운로드 받을때 한글이 깨지는 경우가 발생합니다.
그럴때는 아래 검은색으로 표시한것처럼 처리해주면 됩니다.
@RequestMapping("/mngt/image/download") public void mngtImageDownload(@RequestParam Map<String,Object> reqVo, HttpServletResponse response, HttpServletRequest request){
String urlPath = (String) reqVo.get("urlPath"); //full경로 String fileName = (String) reqVo.get("fileName"); //파일명
try { fileName = new String (fileName.getBytes("UTF-8"),"ISO-8859-1"); URL url = new URL(urlPath); response.setHeader("Content-disposition", "attachment;filename=" + fileName); response.setContentType("application/octer-stream"); InputStream is = url.openStream(); BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream()); int len; byte[] buf = new byte[1024]; while ( (len = is.read(buf)) > 0 ) { outs.write(buf, 0, len); } outs.close(); } catch (MalformedURLException e) { logger.error("Error ModelAndView.viewMain - MalformedURLException : " + e.toString() + " -- " + e.getStackTrace()[0].toString()); } catch (IOException e) { logger.error("Error ModelAndView.viewMain - IOException : " + e.toString() + " -- " + e.getStackTrace()[0].toString()); }
} |