• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
chominsoo4245 / mjon_git star
Forked from hylee / mjon_git
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB
  • Files
  • Commit
  • Branches
mjon_gitsrcmainjavaitncomcmmwebEgovFileDownloadController.java
Download as .zip file
File name
Commit message
Commit date
DATABASE
mjon_git
2023-06-12
src/main
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
.codetogether.ignore
mjon_git
2023-06-12
.gitignore
gitignore 적용
2023-06-12
pom.xml
mjon_git
2023-06-12
File name
Commit message
Commit date
java
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
resources
회원 탈퇴자 관리 통계 추가
2023-06-26
webapp
주소록 관리 문자 주소록 개별 등록시 핸드폰 및 일반전화 유효성 체크 스크립트 추가
2023-07-03
File name
Commit message
Commit date
egovframework
mjon_git
2023-06-12
itn
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
File name
Commit message
Commit date
com
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
let
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
web
전용계좌 첫결제시 스미싱알림 처리
2023-06-26
File name
Commit message
Commit date
api/web
mjon_git
2023-06-12
cmm
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
sym/log/ulg
mjon_git
2023-06-12
usr/search/web
mjon_git
2023-06-12
uss
mjon_git
2023-06-12
utl
mjon_git
2023-06-12
File name
Commit message
Commit date
aspect
mjon_git
2023-06-12
captcha
mjon_git
2023-06-12
filter
mjon_git
2023-06-12
interceptor
IPIgnore Interceptor IPv4/IPv6 모두 체크되도록 기능 수정
2023-07-03
service
mjon_git
2023-06-12
taglibs
mjon_git
2023-06-12
util
문자전송, 선거문자 하단 문자샘플, 그림샘플, 내문자함 검색어 입력 특수문자 입력 금지 기능 추가 - 기존 헤더부분 통합검색에만 적용되었던 기능을 확대 적용하였음.
2023-07-03
web
mjon_git
2023-06-12
AltibaseClobStringTypeHandler.java
mjon_git
2023-06-12
ComDefaultCodeVO.java
mjon_git
2023-06-12
ComDefaultVO.java
mjon_git
2023-06-12
EgovComCrossSiteHndlr.java
mjon_git
2023-06-12
EgovComExcepHndlr.java
mjon_git
2023-06-12
EgovComOthersExcepHndlr.java
mjon_git
2023-06-12
EgovComTraceHandler.java
mjon_git
2023-06-12
EgovMessageSource.java
mjon_git
2023-06-12
EgovMultiPartEmail.java
mjon_git
2023-06-12
EgovWebUtil.java
mjon_git
2023-06-12
ImagePaginationRenderer.java
mjon_git
2023-06-12
ImagePaginationRendererWeb.java
mjon_git
2023-06-12
JsonResult.java
mjon_git
2023-06-12
LoginVO.java
mjon_git
2023-06-12
ReadVO.java
mjon_git
2023-06-12
SessionVO.java
mjon_git
2023-06-12
UserVO.java
mjon_git
2023-06-12
File name
Commit message
Commit date
EgovBindingInitializer.java
mjon_git
2023-06-12
EgovComUtlController.java
mjon_git
2023-06-12
EgovFileDownloadController.java
mjon_git
2023-06-12
EgovFileMngController.java
mjon_git
2023-06-12
EgovImageProcessController.java
mjon_git
2023-06-12
EgovMultipartResolver.java
mjon_git
2023-06-12
hylee 2023-06-12 3d8054f mjon_git UNIX
Raw Open in browser Change history
package itn.com.cmm.web; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.Map; import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper; import itn.com.cmm.service.EgovFileMngService; import itn.com.cmm.service.FileVO; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; /** * 파일 다운로드를 위한 컨트롤러 클래스 * @author 공통서비스개발팀 이삼섭 * @since 2009.06.01 * @version 1.0 * @see * * <pre> * << 개정이력(Modification Information) >> * * 수정일 수정자 수정내용 * ------- -------- --------------------------- * 2009.3.25 이삼섭 최초 생성 * * Copyright (C) 2009 by MOPAS All right reserved. * </pre> */ @Controller public class EgovFileDownloadController { @Resource(name = "EgovFileMngService") private EgovFileMngService fileService; @Value("#{globalSettings['Globals.file.saveDir']}") private String fileSaveDir; private static final Logger LOGGER = LoggerFactory.getLogger(EgovFileDownloadController.class); /** * 브라우저 구분 얻기. * * @param request * @return */ private String getBrowser(HttpServletRequest request) { String header = request.getHeader("User-Agent"); if (header.indexOf("MSIE") > -1) { return "MSIE"; } else if (header.indexOf("Trident") > -1) { // IE11 문자열 깨짐 방지 return "Trident"; } else if (header.indexOf("Chrome") > -1) { return "Chrome"; } else if (header.indexOf("Opera") > -1) { return "Opera"; } return "Firefox"; } /** * Disposition 지정하기. * * @param filename * @param request * @param response * @throws Exception */ private void setDisposition(String filename, HttpServletRequest request, HttpServletResponse response) throws Exception { String browser = getBrowser(request); String dispositionPrefix = "attachment; filename="; String encodedFilename = null; if (browser.equals("MSIE")) { encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20"); } else if (browser.equals("Trident")) { // IE11 문자열 깨짐 방지 encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20"); } else if (browser.equals("Firefox")) { encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\""; } else if (browser.equals("Opera")) { encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\""; } else if (browser.equals("Chrome")) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < filename.length(); i++) { char c = filename.charAt(i); if (c > '~') { sb.append(URLEncoder.encode("" + c, "UTF-8")); } else { sb.append(c); } } encodedFilename = sb.toString(); } else { //throw new RuntimeException("Not supported browser"); throw new IOException("Not supported browser"); } response.setHeader("Content-Disposition", dispositionPrefix + encodedFilename); if ("Opera".equals(browser)) { response.setContentType("application/octet-stream;charset=UTF-8"); } } /** * 첨부파일로 등록된 파일에 대하여 다운로드를 제공한다. * * @param commandMap * @param response * @throws Exception */ @RequestMapping(value = "/cmm/fms/FileDown.do") public void cvplFileDownload(@RequestParam Map<String, Object> commandMap, HttpServletRequest request, HttpServletResponse response) throws Exception { String atchFileId = (String) commandMap.get("atchFileId"); String fileSn = (String) commandMap.get("fileSn"); /*Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();*/ /*if (isAuthenticated) {*/ FileVO fileVO = new FileVO(); fileVO.setAtchFileId(atchFileId); fileVO.setFileSn(fileSn); FileVO fvo = fileService.selectFileInf(fileVO); if(fvo == null){ response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br></h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); return ; } File uFile = new File(fvo.getFileStreCours(), fvo.getStreFileNm()); long fSize = uFile.length(); if (fSize > 0) { String mimetype = "application/x-msdownload"; response.setContentType(mimetype); setDisposition(fvo.getOrignlFileNm(), request, response); //response.setContentLength(fSize); BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(uFile)); out = new BufferedOutputStream(response.getOutputStream()); FileCopyUtils.copy(in, out); out.flush(); } catch (Exception ex) { LOGGER.debug("IGNORED: {}", ex.getMessage()); } finally { if (in != null) { try { in.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } if (out != null) { try { out.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } } } else { response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br>" + fvo.getOrignlFileNm() + "</h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); } /*}*/ } /** * 첨부파일로 등록된 셈플파일에 대하여 다운로드를 제공한다. * * @param commandMap * @param response * @throws Exception */ @RequestMapping(value = "/cmm/fms/CustomSampleFileDown.do") public void customSampleFileDown(@RequestParam Map<String, Object> commandMap, HttpServletRequest request, HttpServletResponse response) throws Exception { String atchFileId = (String) commandMap.get("atchFileId"); String fileSn = (String) commandMap.get("fileSn"); FileVO fileVO = new FileVO(); fileVO.setAtchFileId(atchFileId); fileVO.setFileSn(fileSn); FileVO fvo = fileService.selectFileInf(fileVO); if(fvo == null){ response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br></h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); return ; } String imagePath = ""; String fileNm = fvo.getStreFileNm()+"."+fvo.getFileExtsn(); //로컬 과 개발서버의 이미지 저장 경로 분기처리 if(request.getServerName().equals("localhost")) { imagePath = fvo.getFileStreCours()+"/"; }else { /*imagePath = "/usr/local/tomcat_mjon/webapps/mjon/MMS/" +fvo.getFileStreCours();*/ imagePath = fvo.getFileStreCours()+"/"; } File uFile = new File(imagePath, fileNm); long fSize = uFile.length(); if (fSize > 0) { String mimetype = "application/x-msdownload"; response.setContentType(mimetype); setDisposition(fvo.getOrignlFileNm(), request, response); //response.setContentLength(fSize); BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(uFile)); out = new BufferedOutputStream(response.getOutputStream()); FileCopyUtils.copy(in, out); out.flush(); } catch (Exception ex) { LOGGER.debug("IGNORED: {}", ex.getMessage()); } finally { if (in != null) { try { in.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } if (out != null) { try { out.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } } } else { response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br>" + fvo.getOrignlFileNm() + "</h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); } } /** * 첨부파일로 등록된 PDF파일을 미리보기 한다. * * @param commandMap * @param response * @throws Exception */ @RequestMapping(value = "/cmm/fms/pdfView.do") public void pdfView(@RequestParam Map<String, Object> commandMap, HttpServletRequest request, HttpServletResponse response) throws Exception { String atchFileId = (String) commandMap.get("atchFileId"); String fileSn = (String) commandMap.get("fileSn"); FileVO fileVO = new FileVO(); fileVO.setAtchFileId(atchFileId); fileVO.setFileSn(fileSn); FileVO fvo = fileService.selectFileInf(fileVO); if(fvo == null){ response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br></h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); return ; } FileInputStream fis = null; BufferedOutputStream bos = null; try{ /* String pdfFileName = "C:/upload/TEST.pdf"; File pdfFile = new File(pdfFileName);*/ File pdfFile = new File(fvo.getFileStreCours(), fvo.getStreFileNm()); //클라이언트 브라우져에서 바로 보는 방법(헤더 변경) response.setContentType("application/pdf"); //★ 이 구문이 있으면 [다운로드], 이 구문이 없다면 바로 target 지정된 곳에 view 해줍니다. //response.addHeader("Content-Disposition", "attachment; filename="+pdfFile.getName()+".pdf"); //파일 읽고 쓰는 건 일반적인 Write방식이랑 동일합니다. 다만 reponse 출력 스트림 객체에 write. fis = new FileInputStream(pdfFile); int size = fis.available(); //지정 파일에서 읽을 수 있는 바이트 수를 반환 byte[] buf = new byte[size]; //버퍼설정 int readCount = fis.read(buf); response.flushBuffer(); bos = new BufferedOutputStream(response.getOutputStream()); bos.write(buf, 0, readCount); bos.flush(); } catch(Exception e) { e.printStackTrace(); } finally { try{ if (fis != null) fis.close(); //close는 꼭! 반드시! if (bos != null) bos.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * 첨부파일로 등록된 PDF파일을 미리보기 한다. * * @param commandMap * @param response * @throws Exception */ @RequestMapping(value = "/cmm/fms/attachFilePreview.do") public void contentPreview(@RequestParam Map<String, Object> commandMap, HttpServletRequest request, HttpServletResponse response) throws Exception { String atchFileId = (String) commandMap.get("atchFileId"); String atchFileType = (String) commandMap.get("atchFileType"); String fileSn = (String) commandMap.get("fileSn"); FileVO fileVO = new FileVO(); fileVO.setAtchFileId(atchFileId); fileVO.setFileSn(fileSn); FileVO fvo = fileService.selectFileInf(fileVO); if(fvo == null){ response.setContentType("application/x-msdownload"); PrintWriter printwriter = response.getWriter(); printwriter.println("<html>"); printwriter.println("<br><br><br><h2>Could not get file name:<br></h2>"); printwriter.println("<br><br><br><center><h3><a href='javascript: history.go(-1)'>Back</a></h3></center>"); printwriter.println("<br><br><br>&copy; webAccess"); printwriter.println("</html>"); printwriter.flush(); printwriter.close(); return ; } FileInputStream fis = null; BufferedOutputStream bos = null; try{ /* String pdfFileName = "C:/upload/TEST.pdf"; File pdfFile = new File(pdfFileName);*/ File attachFile = new File(fvo.getFileStreCours(), fvo.getStreFileNm()); /*text/html audio/mpeg image/bmp image/jpeg application/pdf application/java application/jar application/x-zip application/msword application/msaccess application/vnd.ms-excel application/vnd.ms-powerpoint application/octet-stream*/ if(atchFileType.equals("pdf")){ atchFileType = "application/pdf" ; }else if(atchFileType.equals("xls")) { atchFileType = "application/vnd.ms-excel" ; }else if(atchFileType.equals("word")) { atchFileType = "application/msword" ; }else if(atchFileType.equals("ppt")) { atchFileType = "application/vnd.ms-powerpoint" ; }else if(atchFileType.equals("jpg")) { atchFileType = "image/jpeg" ; }else if(atchFileType.equals("bmp")) { atchFileType = "image/bmp" ; } //클라이언트 브라우져에서 바로 보는 방법(헤더 변경) //response.setContentType("application/pdf"); response.setContentType(atchFileType); //★ 이 구문이 있으면 [다운로드], 이 구문이 없다면 바로 target 지정된 곳에 view 해줍니다. //response.addHeader("Content-Disposition", "attachment; filename="+pdfFile.getName()+".pdf"); //파일 읽고 쓰는 건 일반적인 Write방식이랑 동일합니다. 다만 reponse 출력 스트림 객체에 write. fis = new FileInputStream(attachFile); int size = fis.available(); //지정 파일에서 읽을 수 있는 바이트 수를 반환 byte[] buf = new byte[size]; //버퍼설정 int readCount = fis.read(buf); response.flushBuffer(); bos = new BufferedOutputStream(response.getOutputStream()); bos.write(buf, 0, readCount); bos.flush(); } catch(Exception e) { e.printStackTrace(); } finally { try{ if (fis != null) fis.close(); //close는 꼭! 반드시! if (bos != null) bos.close(); } catch (IOException e) { e.printStackTrace(); } } } }

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up