if(file["DATA"].length > 0 && null != file["DATA"].length && file["DATA"].length != 'undefine'){
for(var i=0;i<file["DATA"].length;i++){
fileName = file["DATA"][i]["FILE_NM"];
path = file["DATA"][i]["FILE_PATH"];
fileSeq = file["DATA"][i]["FILE_SEQ"];
img = isExpImg(fileName);
list += "<img src='${ctx}/common/images/common/icon/"+img+"'> ";
list += "<A HREF=javascript:jsGetFile('"+path+"','"+fileName+"');>"+fileName+"</A> ";
list += "<A HREF=javascript:jsDelFile('"+fileSeq+"','"+path+"','"+fileName+"'); >";
list += "<img src='${ctx}/common/images/common/button/btn_delete.gif' >";
list += "</A><br>";
}
$("#fileList").html(list);
}
------------------------------------------------------------------------------------------------------------------------------------------------------
function jsGetFile(path,fileName){
frm = document.fileForm;
frm.path.value = path;
frm.fileName.value = fileName;
frm.action = "${ctx}/download.do";
frm.submit();
}
------------------------------------------------------------------------------------------------------------------------------------------------------
<%@ page import="java.io.File" %>
<%@ page import="java.io.*"%>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Properties" %>
<%@ 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>
<%
BufferedInputStream fin = null;
BufferedOutputStream outs = null;
try{
String fileName = request.getParameter("fileName");
String realFolder = request.getParameter("path");
Properties properties = new Properties();
String saveFolder = "";
try {
InputStream is = getClass().getResourceAsStream("/hrintro/properties/fileUpload.properties");
properties.load(is);
//saveFolder = properties.getProperty("file.upload.path") + properties.getProperty(realFolder);
saveFolder = properties.getProperty("file.upload.path") + realFolder;
} catch (IOException e) {
//e.toString();
}
System.out.println("filePath >> " + saveFolder);
System.out.println("fileName encode before >> " + fileName);
response.setContentType("application/octet-stream");
String filePath = saveFolder + "\\" + fileName;
System.out.println("User-Agent : " + request.getHeader("User-Agent"));
/* if (request.getHeader("User-Agent").indexOf("Trident") > -1) {
System.out.println("fileName1 === > " + fileName);
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
}
System.out.println("fileName2 === > " + fileName);
*/
boolean ie = request.getHeader("User-Agent").indexOf("MSIE") != -1;
if (ie) {
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", " ");
} else {
//fileName = new String(fileName.getBytes("UTF-8"), "8859_1");
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
}
System.out.println("fileName encode after >> " + fileName);
out.clear();
out = pageContext.pushBody();
File file = new File(filePath);
byte b[] = new byte[(int)file.length()];
String strClient=request.getHeader("User-Agent");
response.setHeader("Content-Disposition","attachment;filename="+fileName+";");
if (file.isFile() && file.length()>0){
fin = new BufferedInputStream(new FileInputStream(file));
outs = new BufferedOutputStream(response.getOutputStream());
int read = 0;
while ((read = fin.read(b)) != -1){
outs.write(b,0,read);
}
outs.close();
fin.close();
}
}catch(Exception e) {
System.out.println("오류내용 : " + e.getMessage());
}finally{
if(outs!=null) outs.close();
if(fin!=null) fin.close();
}
%>
----------------------------------------------------------------------------------------------------------------------------------------------------
@RequestMapping(value="/download.do")
public String download(String fileName, Model model) {
model.addAttribute("fileName", fileName);
return "download";
}