작업환경

 eGovFramework Version : 3.8

Eclipse Version : Oxygen.3a Release (4.7.3a)

JDK Version : 1.8

1. 파일 업로드

 

1.1 화면 구성

 

egovframework에서 파일 업로드 기능을 찾아보면 화면 구현 방법은 2가지로 만들 수 있습니다업로드 파일의 최대 개수를 정하고 필요한 만큼만 선택 계속 선택해서 한번에 묶어 보내는 방법과 각각의 파일을 하나씩만 선택 할 수 있도록 file tag를 사용하여 보내는 방법이 있습니다.  첫 번째 방법은 파일의 개수를 정하고 하단이 파일명으로 늘어나는 것을 감안하여 디자인이 되어야 하고, 두 번째 방법은 사용하지도 않을 수 있는 전송할 파일의 수만큼 미리 입력 화면을 고정해야 하는 단점이 있습니다간단한 화면 구성을 살펴 보면 아래와 같습니다.



egovframework upload download


다중 파일 업로드는 파일선택 버튼이 한 개만 존재 하고 이 버튼을 이용하여 파일을 선택하면 하단에 계속해서 파일 리스트가 추가 됩니다잘못 선택된 파일이 있다면 delete 버튼으로 삭제 합니다그리고 파일 선택이 완료 되었으면 저장 버튼을 이용하여 선택된 파일들을 서버로 전달하면 됩니다.

 

단일 파일 업로드 방식은 필요한 개수만큼 파일선택 버튼을 추가하고 저장버튼을 클릭하여 선택된 파일들을 서버로 전달 합니다.

파일을 선택한 경우의 화면은 아래 이미지 처럼 보입니다.


egovframework upload download


다중파일은 이미지 4개를 선택하고 단일파일은 각각 파일을 선택해 보았습니다.

 

1.2  JSP 파일

 

1.2.1 다중 파일 업로드

 

다중 파일 업로드를 구현 하려면 상단에 js 파일을 하나 추가해야 합니다.


<script type="text/javascript" src="<c:url value='/js/egovframework/com/cmm/fms/EgovMultiFile.js'/>" ></script>


파일을 선택하는 부분은 일반 file tag를 사용하는데 <input type="hidden" name="atchPosblFileNumber" id="atchPosblFileNumber" value="5" /> 이런 식으로 최대 파일 개수를 입력 합니다여기서는 5개로 설정 하였습니다.


egovframework upload download


<input type="hidden" name="savePath" value="Globals.fileTest1Path" /> 이건 파일을 저장하기 위한 위치를 설정하는 부분으로 Server 부분 소스 설명에 나와 있습니다.

 

선택한 파일을 리스트로 보여주는 부분은 javascript로 구현이 되어 있습니다.


egovframework upload download


form 에서 최대 파일 개수를 정하지 않았다면 기본값을 설정할 수도 있고 여기서는 3으로 했습니다.

 

 

1.2.2 단일 파일 업로드

 

단일 파일 업로드는 기존에 사용하는 file tag와 동일 하게 테그 하나에 파일 하나를 추가하는 방식으로 JSP 파일을 작성 합니다.


egovframework upload download


1.3 Server 작업

 

1.3.1 설정


파일을 저장할 위치를 설정 합니다.

Globals.properties

 # 파일 업로드 경로(경로 설정은 반드시 절대경로를 사용해야함, 경로 뒤에 / 붙여 주어야함.)

Globals.fileStorePath =C:/egovframework/upload/

Globals.fileTest1Path =C:/egovframework/upload/filepath1/

Globals.fileTest2Path =C:/egovframework/upload/filepath2/


1.3.2 Controller 생성


임의의 controller를 생성하고 화면에서 호출하는 주소를 입력 합니다.


egovframework upload download


다중 또는 단일 파일 업로드로 화면에서 파일을 보내주면 Server에서는 동일한 로직으로 처리하기 때문에 하나의 함수만 작성하면 됩니다


egovframework upload download


파일을 폴더에 저장한 후에는 결과를 2개의 Table에 반영 합니다.


업로드 정보를 저장하고

select * from COMTNFILE;


egovframework upload download


실제 저장된 파일 정보가 저장 됩니다.

select * from COMTNFILEDETAIL;


egovframework upload download


단일 업로드도 동일한 방법으로 저장이 됩니다. 

 

2. 파일 다운로드

 

2.1 jsp 파일

 

파일 업로드 정보를 담고 있는 테이블에서 ATCH_FILE_IDFILE_SNparam으로 넣어주면 다운로드를 할 수 있습니다.


egovframework upload download


/cmm/fms/FileDown.do에서 넘겨준 param을 이용하여 FileVO에 담아 상세 정보를 이용하여 원래 파일 명을 찾아 다운로드를 진행 합니다.



3. 전체 파일 

3.1 jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

 

<script type="text/javascript" src="<c:url value='/js/egovframework/com/cmm/fms/EgovMultiFile.js'/>" ></script>

 

 

<title>Insert title here</title>

<link type="text/css" rel="stylesheet" href="<c:url value='/css/egovframework/com/com.css' />">

</head>

<body>

 

<br>

<br>

<br>

 

<h2>다중 파일 업로드</h2>

<form name="frm" method="post" action="<c:url value='/file/fileUpload.do'/>" enctype="multipart/form-data" >

   <input type="hidden" name="atchPosblFileNumber" id="atchPosblFileNumber" value="5" />

   <input type="hidden" name="savePath" value="Globals.fileTest1Path" />

  

   <table width="400px" cellspacing="0" cellpadding="0" border="1" >

           <tr>

            <td ><input name="file_1" id="egovComFileUploader" type="file" />

                <div id="egovComFileList"></div>

            </td>

           </tr>

           <tr>

            <td align="center">

                <input type="submit" value="저장">

            </td>

           </tr>

        </table>      

</form>

 

<!-- 첨부파일 업로드 가능화일 리스트설 Start..--> 

<script type="text/javascript">

var maxFileNum = document.getElementById('atchPosblFileNumber').value;

if(maxFileNum==null || maxFileNum==""){

        maxFileNum = 3;

}

var multi_selector = new MultiSelector( document.getElementById( 'egovComFileList' ), maxFileNum );

multi_selector.addElement( document.getElementById( 'egovComFileUploader' ) );

</script>

<!-- 첨부파일 업로드 가능화일 리스트 End.--> 

<p>

<h2>단일파일 업로드</h2>

<form id="frm2" action="<c:url value='/file/fileUpload.do'/>" method="post" enctype="multipart/form-data">

        <input type="hidden" name="savePath" value="Globals.fileTest2Path" />

        <table width="400px" cellspacing="0" cellpadding="0" border="1" >

               <tr>

                   <td >

                              <input type="file" name="file1" /><br>

                              <input type="file" name="file2" /><br>

                       </td>

               </tr>

               <tr>

                       <td align="center">

                              <input type="submit" value="저장">

                       </td>

           </tr>

        </table>

 </form>

 

<p>

<p>

<p>

 

 

<a href="javascript:fn_egov_downFile('FILE_000000000000201','0')">

 파일 다운로드

</a>

 

<script type="text/javascript">

 

        function fn_egov_downFile(atchFileId, fileSn){

               window.open("<c:url value='/cmm/fms/FileDown.do?atchFileId="+atchFileId+"&fileSn="+fileSn+"'/>");

        }

</script>

  

 

</body>

</html> 


3.2 Controller


package copycoding.com.util.file.web;

 

import java.util.List;

import java.util.Map;

 

import javax.annotation.Resource;

import javax.servlet.http.HttpServletRequest;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.support.SessionStatus;

import org.springframework.web.multipart.MultipartFile;

import org.springframework.web.multipart.MultipartHttpServletRequest;

 

import egovframework.com.cmm.SessionVO;

import egovframework.com.cmm.service.EgovFileMngService;

import egovframework.com.cmm.service.EgovFileMngUtil;

import egovframework.com.cmm.service.FileVO;

 

@Controller

public class FileUploadDownloadController {

           @Resource(name="EgovFileMngService")

           private EgovFileMngService fileMngService;

          

           @Resource(name="EgovFileMngUtil")

           private EgovFileMngUtil fileUtil;

          

           @RequestMapping(value = "/file/fileUpDownloadTest.do")

           public String daumEditor(ModelMap model) throws Exception {

                     return "copycoding/util/FileUpDownload";

           }

          

           @RequestMapping(value = "/file/fileUpload.do")

           public String uploadSingleFile(

                                final MultipartHttpServletRequest multiRequest,

                                HttpServletRequest request,

                                SessionVO sessionVO,

                                ModelMap model,

                                SessionStatus status) throws Exception{

                      

                                String storePath = request.getParameter("savePath");

                                List<FileVO> result = null;

                                String atchFileId = "";

                                final Map<String, MultipartFile> files = multiRequest.getFileMap();

                               

                                if(!files.isEmpty()){

                                          // 파일 객체, 구분 값, 파일 순번, 파일ID, 저장경로

                                          result = fileUtil.parseFileInf(files, "upfile_", 0, "", storePath);

                                          //파일이 생성되고나면 생성된 첨부파일 ID를 리턴한다.

                                          atchFileId = fileMngService.insertFileInfs(result); 

                                }

                      

                                return null;

           }

}


- copy coding -

작업환경

 eGovFramework Version : 3.8

Eclipse Version : Oxygen.3a Release (4.7.3a)

JDK Version : 1.8


프로젝트를 진행하다 보면 업무를 구분하기 위하여 package를 여러개 만들어야 하는 상황이 발생 합니다.  특히 전자정부프레임워크를 사용하여 개발을 진행할 때에는 기존 egovframework package와 신규로 추가되는 package를 구분하여 작업을 해야 하는 상황이 자주 발생 합니다.  사실 신규 package를 추가하는 방법은 상당히 간단 합니다.

 

egovframework package


설정 xml 수정

base package와 관련된 설정 xml 파일 3개를 수정 합니다. 수정이라기 보다는 신규 package를 등록하는 작업을 진행 합니다. base-package를 등록하면 그 하단의 파일들이 등록이 됩니다.

 

- context-common.xml

/CopyCoding/src/main/resources/egovframework/spring/com/context-common.xml

 <context:component-scan base-package="egovframework, copycoding">

<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>

<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

</context:component-scan>

copycoding 이라는 package를 콤마를 이용하여 추가해주면 적용이 됩니다.


- egov-com-servlet.xml

/ CopyCoding/src/main/webapp/WEB-INF/config/egovframework/springmvc/egov-com-servlet.xml

 <context:component-scan base-package="egovframework, copycoding">

<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>

</context:component-scan>

여기에도 콤마를 이용하여 추가하려는 패키지 최 상단명을 입력합니다.


위에 두개의 xml 파일을 수정하여 설정은 완료 되었고 그 외에 필요한 aspect 또는 filter등의 설정 파일이 있다면 그곳도 추가를 해주면 됩니다방법은 기존에 있는 설정을 복사하여 추가하면 됩니다.

 

context-aspect.xml

/admin/src/main/resources/egovframework/spring/com/context-aspect.xml

 <aop:config>

<aop:pointcut id="egov.serviceMethod" expression="execution(* egovframework.com..impl.*Impl.*(..)) or execution(* copycoding.com..impl.*Impl.*(..))" />

 

<aop:aspect ref="egov.exceptionTransfer">

        <aop:after-throwing throwing="exception" pointcut-ref="egov.serviceMethod" method="transfer" />

</aop:aspect>

</aop:config>


이렇게 or를 사용하여 추가해주면 설정이 끝나고 필요한 파일들을 추가해서 작업을 진행 합니다.


- copy coding -


작업 환경

eGovFramework Version : 3.8

Eclipse Version: Oxygen.3a Release (4.7.3a)

JDK Version : 1.8

 

오류 내용

전자정부프레임워크에서 Web Project 생성 하고 common component 설치 Run on Server 하는 경우 No bean named 'egovPopupManageIdGnrService' available 오류가 발생하는 경우가 있습니다.  


[log4j]2019-08-17 11:12:11,408  WARN [org.springframework.web.context.support.XmlWebApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'egovPopupManageService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'egovPopupManageIdGnrService' available

8 17, 2019 11:12:11 오전 org.apache.catalina.core.ContainerBase startInternal

심각: A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CopyCoding]] 


해결 방법

common component 자동 설치 하는 동안 파일이 제대로 설치가 되지 않아 발생하는 오류입니다이런 경우도 All in One Template 버전을 설치 하거나 소스를 다운받아 압축을 풀어 놓고 참조하면서 작업을 하면 쉽게 처리할 있습니다.

해결 방법은 간하게 파일을 복사 하면 됩니다

/src/main/resources/egovframework/spring/com/idgn/context-idgn-PopupManage.xml


eGovFramework egovPopupManageIdGnrService


전체 소스가 들어있는 프로젝트의 resources 하단 egovframework/spring/com/idgn 폴더에서 context-idgn-PopupManage.xml 파일을 복사하여 작업 중인 프로젝트에 붙여넣기를 하면 됩니다붙여넣기를 했으면 다시한번 Run on Server 실행해 봅니다.


eGovFramework egovPopupManageIdGnrService


오류 없이 로그인 화면까지 진행 됩니다.


- copy coding -

작업 환경


eGovFramework Version : 3.8

Eclipse Version: Oxygen.3a Release (4.7.3a)

JDK Version : 1.8


오류 내용


전자정부프레임워크 Project에서 common component 설치 Maven install 하는 경우 package egovframework.com.uss.ion.pwm.web does not exist 오류가 발생하는 경우가 있습니다.  


 [ERROR] COMPILATION ERROR : 

[INFO] -------------------------------------------------------------

[ERROR] /C:/eGovFrameDev/workspace5/CopyCoding/src/main/java/egovframework/com/cop/cmy/web/EgovCommuManageController.java:[34,41] package egovframework.com.uss.ion.pwm.web does not exist

[INFO] 1 error

[INFO] -------------------------------------------------------------

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------


common component 자동 설치 하는 동안 파일이 제대로 설치가 되지 않아 발생하는 오류입니다. All in One Template 버전을 하나 설치해서 참조 하거나 common component 소스를 다운받아 압축을 풀어 놓고 참조하면서 작업을 해야 합니다.

해결 방법은 간단 합니다소스가 설치되니 않은 것이니 빠진 파일을 찾아 복사 하면 됩니다


package 생성


먼저 package 생성 합니다. egovframework.com.uss.ion.pwm


uss.ion.pwm.web does not exist



파일 복사

그리고 파일을 복사 합니다. 파일을 복사한 후의 모습 입니다.


uss.ion.pwm.web does not exist


다시 한번 Maven install 실행 합니다.


uss.ion.pwm.web does not exist


오류가 나지 않고 성공 입니다.


12

+ Recent posts