이지우 > 관리자 > 분쟁조정관련서식 > 기존 다운로드 구현 완료 및

This commit is contained in:
JIWOO 2024-10-29 18:34:05 +09:00
parent fa9585dc14
commit 510c2e1c17
5 changed files with 118 additions and 5 deletions

View File

@ -0,0 +1,85 @@
package seed.com.gtm.seedfile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.servlet.view.AbstractView;
public class FileDownloadView extends AbstractView {
public FileDownloadView(){
setContentType("application/download; charset=utf-8");
}
@Override
protected void renderMergedOutputModel(Map<String, Object> map,
HttpServletRequest request, HttpServletResponse response) throws Exception {
boolean success = false;
String fileReName = (String)map.get("fileReName");
String fileName = (String)map.get("fileName");
String filePath = (String)map.get("filePath");
try{
if(!"".equals(fileReName)){
File file = null;
FileInputStream fin = null;
OutputStream out = null;
try{
file = new File(filePath, fileReName);
response.setContentType(getContentType());
response.setContentLength((int)file.length());
String client = request.getHeader("User-Agent");
if(client.indexOf("MSIE") != -1 || client.indexOf("Trident") != -1){
response.setHeader ("Content-Disposition", "attachment; filename="+new String(fileName.getBytes("KSC5601"),"ISO8859_1"));
}else{
fileName = new String(fileName.getBytes("utf-8"),"iso-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
}
response.setHeader("Content-Transfer-Encoding", "binary");
out = response.getOutputStream();
fin = new FileInputStream(file);
FileCopyUtils.copy(fin, out);
}catch(UnsupportedEncodingException e){
System.out.println("UnsupportedEncodingException Error");
}catch(FileNotFoundException e){
System.out.println("FileNotFoundException Error");
}catch(IOException e){
System.out.println("IOException Error");
}catch(Exception e){
System.out.println("Exception Error");
}finally{
if(fin!=null)try{fin.close();}catch(Exception e){}
if(out!=null)try{out.close();}catch(Exception e){}
}
}
}catch(NullPointerException e){
System.out.println("download.jsp 파일에서 에러 발생 NullPointerException");
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("download.jsp 파일 부분 에러 발생 ArrayIndexOutOfBoundsException");
}finally{
}
}
}

View File

@ -217,7 +217,7 @@ public class SeedFileController {
SeedProperties seedProperties = new SeedProperties(); SeedProperties seedProperties = new SeedProperties();
/*String rootPath = seedProperties.getConfigValue("file.real.path");*/ /*String rootPath = seedProperties.getConfigValue("file.real.path");*/
String rootPath = globalRootPath; String rootPath = globalRealPath;
String dataIdx = SeedUtils.setReplaceNull(paramMap.get("dataIdx")); String dataIdx = SeedUtils.setReplaceNull(paramMap.get("dataIdx"));
String pathKey1 = SeedUtils.setReplaceNull(paramMap.get("pathKey1")); String pathKey1 = SeedUtils.setReplaceNull(paramMap.get("pathKey1"));

View File

@ -1,6 +1,7 @@
package seed.com.gtm.seedfile; package seed.com.gtm.seedfile;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -79,8 +80,7 @@ public class SeedFileService {
String toDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMdd"); String toDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMdd");
String renameDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMddHHmmss"); String renameDate = seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMddHHmmss");
/*SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+ "/" +fileFuncType);*/ SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+"/"+ fileFuncType);
SeedUtils.setSeedMkDirs(rootPath + "/"+siteIdx+ fileFuncType);
int fileCnt = 0; int fileCnt = 0;
@ -118,6 +118,21 @@ public class SeedFileService {
filePath = rootPath + "/"+siteIdx+"/upload/uploadFiles/"+fileFuncType+"/"+reFileName+"."+fileType; filePath = rootPath + "/"+siteIdx+"/upload/uploadFiles/"+fileFuncType+"/"+reFileName+"."+fileType;
}else{ }else{
//241029 - 첨부파일 복사를 위해 real 파일 생성 처리
/* File makeFile = null;
makeFile = new File(rootPath + "/"+siteIdx+"/"+fileFuncType+"/"+reFileName);
if(! makeFile.exists()){
//경로에 해당하는 디렉토리들을 생성
if(makeFile.getParentFile().mkdirs()){
try {
makeFile.createNewFile(); //이후 파일 생성
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}*/
SeedUtils.setSeedFileCopy(tempPath + "/"+siteIdx+"/"+fileFuncType + "/" + uploadFileReNameData, SeedUtils.setSeedFileCopy(tempPath + "/"+siteIdx+"/"+fileFuncType + "/" + uploadFileReNameData,
rootPath + "/"+siteIdx+"/"+fileFuncType+"/"+reFileName+"."+fileType); rootPath + "/"+siteIdx+"/"+fileFuncType+"/"+reFileName+"."+fileType);

View File

@ -202,7 +202,7 @@ public class SeedUtils {
* Was=서버파일관리 권한이 완전 동일 해야함 * Was=서버파일관리 권한이 완전 동일 해야함
* @param String dirPath 폴더 경로 * @param String dirPath 폴더 경로
*/ */
public static void setSeedMkDirs(String dirPath){ /*public static void setSeedMkDirs(String dirPath){
File file = new File(dirPath); File file = new File(dirPath);
@ -213,7 +213,17 @@ public class SeedUtils {
if(!file.exists()){ if(!file.exists()){
file.mkdirs(); file.mkdirs();
} }
} }*/
public static void setSeedMkDirs(String dirPath) {
File file = new File(dirPath);
if (!file.exists() && !file.isDirectory()) {
if (!file.exists()) {
file.mkdirs();
}
}
}
public static void setSeedFileCopy(String inFileName, String outFileName){ public static void setSeedFileCopy(String inFileName, String outFileName){

View File

@ -43,6 +43,9 @@
</bean> </bean>
<bean id="excelDownloadView" class="kcc.com.cmm.spring.view.ExcelDownloadView"/> <bean id="excelDownloadView" class="kcc.com.cmm.spring.view.ExcelDownloadView"/>
<!-- 분쟁조정 다운로드 시 return되는 파일 -->
<bean id="filedownLoad" class="seed.com.gtm.seedfile.FileDownloadView"/>
<!-- Annotation 을 사용하지 않는 경우에 대한 MVC 처리 설정 --> <!-- Annotation 을 사용하지 않는 경우에 대한 MVC 처리 설정 -->
<mvc:view-controller path="/cmmn/validator.do" view-name="cmmn/validator"/> <mvc:view-controller path="/cmmn/validator.do" view-name="cmmn/validator"/>