<%@ page import="java.io.File"%>
<%@ page import="java.io.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>파일 다운로드</title>
</head>
<body>
<% 
	String filePath = request.getParameter("filePath");
	String fileName = request.getParameter("fileName");
	BufferedInputStream bis = null;
	
	try {
		
		out.clear();
		out = pageContext.pushBody();
		
		byte b[] = new byte[4096];
		
		response.reset();
		response.setContentType("application/octet-stream");
		response.setHeader("Content-Disposition","attachment; filename = " + fileName);
		
		//FileInputStream is = new FileInputStream(filePath+fileName);
		//소스코드점검 수정 20201026
		bis = new BufferedInputStream(new FileInputStream(filePath+fileName)); 
		ServletOutputStream sos = response.getOutputStream();
		
		int numRead;
		while((numRead = bis.read(b, 0, b.length)) != -1) {
			sos.write(b,0,numRead);
		}
		
		sos.flush();
		sos.close();
		
		File file = new File(filePath+fileName);
 		if (file.exists()) file.delete();
 		
	} catch(Exception e) {
		System.out.println(e);		
	} finally {
		if(bis != null) bis.close();
	}
%>
</body>
</html>
