98 lines
3.4 KiB
Plaintext
98 lines
3.4 KiB
Plaintext
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import="java.util.*, java.io.*"%><%@include file="/init.jsp"%><%
|
|
|
|
HashMap map = (HashMap)request.getAttribute("FILE_MAP");
|
|
if(map == null) map = new HashMap();
|
|
|
|
String objId = CommonUtils.checkNull(map.get("OBJID"));
|
|
String targetObjId = CommonUtils.checkNull(map.get("TARGET_OBJID"));
|
|
String savedFileName = CommonUtils.checkNull(map.get("SAVED_FILE_NAME"));
|
|
String realFileName = CommonUtils.checkNull(map.get("REAL_FILE_NAME"));
|
|
String docType = CommonUtils.checkNull(map.get("DOC_TYPE"));
|
|
String docTypeName = CommonUtils.checkNull(map.get("DOC_TYPE_NAME"));
|
|
String fileSize = CommonUtils.checkNull(map.get("FILE_SIZE"));
|
|
String fileExt = CommonUtils.checkNull(map.get("FILE_EXT"));
|
|
String filePath = CommonUtils.checkNull(map.get("FILE_PATH"));
|
|
|
|
if(!"".equals(realFileName)){
|
|
realFileName = (java.net.URLEncoder.encode(realFileName, "UTF-8")).replaceAll("\\+", " ");
|
|
}
|
|
|
|
// 파일 경로 생성
|
|
// savedFileName이 구분자로 시작하면 그대로 합치고, 아니면 구분자 추가
|
|
String fullFilePath = "";
|
|
if(savedFileName.startsWith("/") || savedFileName.startsWith("\\")){
|
|
fullFilePath = filePath + savedFileName;
|
|
} else {
|
|
fullFilePath = filePath + File.separator + savedFileName;
|
|
}
|
|
System.out.println("fullFilePath : "+fullFilePath);
|
|
System.out.println("filePath : "+filePath);
|
|
System.out.println("savedFileName : "+savedFileName);
|
|
System.out.println("realFileName : "+realFileName);
|
|
|
|
File f = new File(fullFilePath);
|
|
|
|
// 파일이 없으면 기존 방식(역슬래시 포함)으로 시도
|
|
if(!f.exists()){
|
|
String legacyFilePath = filePath + "\\" + savedFileName;
|
|
System.out.println("Trying legacy path : "+legacyFilePath);
|
|
File legacyFile = new File(legacyFilePath);
|
|
if(legacyFile.exists()){
|
|
f = legacyFile;
|
|
fullFilePath = legacyFilePath;
|
|
System.out.println("Found with legacy path!");
|
|
}
|
|
}
|
|
if(f.exists()){
|
|
|
|
int filesize = (int)f.length();
|
|
byte buff[] = new byte[2048];
|
|
int bytesRead;
|
|
|
|
try {
|
|
out.clear();
|
|
out=pageContext.pushBody();
|
|
|
|
//response.setContentType("text/plain; charset=EUC_KR");
|
|
//response.setContentType("application/x-msdownload");
|
|
|
|
// PDF 파일이면 미리보기 모드로
|
|
if("PDF".equalsIgnoreCase(fileExt)){
|
|
response.setContentType("application/pdf");
|
|
response.setHeader("Content-Disposition", "inline; filename="+ realFileName);
|
|
}else{
|
|
response.setContentType("application/octet-stream;charset=utf-8");
|
|
response.setHeader("Content-Disposition", "attachment; filename="+ realFileName);
|
|
}
|
|
FileInputStream fin = new java.io.FileInputStream(f);
|
|
BufferedInputStream bis = new BufferedInputStream(fin);
|
|
ServletOutputStream fout = response.getOutputStream();
|
|
BufferedOutputStream bos = new BufferedOutputStream(fout);
|
|
|
|
while((bytesRead = bis.read(buff)) != -1) {
|
|
bos.write(buff, 0, bytesRead);
|
|
}
|
|
bos.flush();
|
|
|
|
fin.close();
|
|
fout.close();
|
|
bis.close();
|
|
bos.close();
|
|
|
|
//file download log 2015-12-22 jmpark start
|
|
Map paramMap = new HashMap();
|
|
paramMap.put("savedFileName", savedFileName);
|
|
paramMap.put("realFileName", realFileName);
|
|
paramMap.put("fileExt", fileExt);
|
|
|
|
//file download log 2015-12-22 jmpark end
|
|
|
|
} catch( IOException e){
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
out.println("Error : "+e.getMessage());
|
|
}
|
|
}else{
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
out.println("File Not Found : " + fullFilePath);
|
|
}
|
|
%> |