<%@ page import="java.io.*, java.util.*" %> <%@ page import="java.net.URLEncoder"%> <%! public void viewImage(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{ HttpSession session = req.getSession(false); System.out.println("viewImage().."); String realFileName = req.getParameter("realFileName"); String savedFileName = req.getParameter("savedFileName"); String attDir = req.getParameter("attDir"); FileInputStream fis = null; //헤더 컨텐츠 타입 설정 res.reset(); res.setContentType("image/jpeg"); realFileName = new String(realFileName.getBytes("EUC-KR"), "ISO-8859-1"); ServletOutputStream out = res.getOutputStream(); try{ //파일 센딩 fis = new FileInputStream(new File(attDir, savedFileName)); byte[] buf = new byte[4*1024]; int bytesRead; while((bytesRead = fis.read(buf)) != -1){ out.write(buf, 0, bytesRead); } }catch(FileNotFoundException e){ out.println("File Not Found"); }catch(IOException e){ out.println("Problem sending file : "+e.getMessage()); }finally{ if(fis != null){ fis.close(); } } } %> <% System.out.println("viewImage.jsp"); out.clear(); out = pageContext.pushBody(); viewImage(request,response); %>