메뉴 건너뛰기

조회 수 5802 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

전자정부표준프레임워크에서 파일 업로드 기능을 구현하는 방법입니다.


[필요파일]

/src/main/java/egovframework/com/cmm/web/EgovMultipartResolver.java

/src/main/java/egovframework/com/cmm/service/EgovFileMngUtil.java

/src/main/java/egovframework/com/cmm/EgovWebUtil.java

/src/main/java/egovframework/com/cmm/service/Globals.java

/src/main/java/egovframework/com/cmm/service/FileVO.java



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


<bean id="local.MultiCommonsMultipartResolver" class="egovframework.com.cmm.web.EgovMultipartResolver">

          <property name="maxUploadSize" value="100000000" />

          <property name="maxInMemorySize" value="100000000" />

</bean>

<alias name="local.MultiCommonsMultipartResolver" alias="multipartResolver" />



[/src/main/resources/egovframework/spring/context-idgen.xml]

테이블 COMTECOPSEQ 이 생성되어 있어야 합니다.


<bean name="egovFileIdGnrService" class="egovframework.rte.fdl.idgnr.impl.EgovTableIdGnrService" 

destroy-method="destroy">

<property name="dataSource" ref="dataSource-oracle" />

<property name="strategy"   ref="fileStrategy" />

<property name="blockSize" value="10"/>

<property name="table"   value="COMTECOPSEQ"/>

<property name="tableName" value="FILE_ID"/>

</bean>

<bean name="fileStrategy" class="egovframework.rte.fdl.idgnr.impl.strategy.EgovIdGnrStrategyImpl">

<property name="prefix" value="FILE_" />

<property name="cipers" value="15" />

<property name="fillChar" value="0" />

</bean>



[/src/main/resources/engovframework/egovProps/globals.properties]

//다음 코드를 삽입한다. (Windows 기준)
Globals.fileStorePath =  e:/temp/


[JSP]
<form name="frmArticle" method="post" enctype="multipart/form-data">
</form>


[Controller]

public String insertTestArticle(Map<String, String> commandMap, HttpServletRequest request, 

ModelMap model) throws Exception {

//파일 업로드

        MultipartHttpServletRequest mptRequest = (MultipartHttpServletRequest)request;

   

Iterator fileIter = mptRequest.getFileNames();


        while (fileIter.hasNext()) {

                 MultipartFile mFile = mptRequest.getFile((String)fileIter.next());


        if (mFile.getSize() > 0) {

                HashMap _map = EgovFileMngUtil.uploadFile(mFile);

                        

    //아래 코드 대신에 데이터베이스에 저장하기 위해서 Map에 담는 코드를 넣으면 된다.

                System.out.println("[ "+Globals.FILE_PATH+" : "+_map.get(Globals.FILE_PATH)+" ]");

        System.out.println("[ "+Globals.FILE_SIZE+" : "+_map.get(Globals.FILE_SIZE)+" ]");

        System.out.println("[ "+Globals.ORIGIN_FILE_NM+" : "+_map.get(Globals.ORIGIN_FILE_NM)+" ]");

        System.out.println("[ "+Globals.UPLOAD_FILE_NM+" : "+_map.get(Globals.UPLOAD_FILE_NM)+" ]");

        System.out.println("[ "+Globals.FILE_EXT+" : "+_map.get(Globals.FILE_EXT)+" ]");

  }

        }

//파일정보를 데이터베이스에 저장하는 코드

...




* 두개 이상의 파일을 업로드할때 동일한 파일을 업로드 하면 egovframework.com.cmm.web.EgovMultipartResolver 에서는 오류가 발생합니다. 동일한 파일을 업로드 하는 것을 허용하기 위해서는  org.springframework.web.multipart.commons.CommonsMultipartResolver 을 사용해야 합니다.


COMTECOPSEQ 테이블 생성문

CREATE TABLE COMTECOPSEQ (table_name varchar(16) NOT NULL,

 next_id DECIMAL(30) NOT NULL,

 PRIMARY_KEY (table_name);

INSERT INTO COMTECOPSEQ VALUES('FILE_ID', '0');



관련글

[eGovFrame] getFileMap() 메소드를 이용한 파일 업로드 기능 구현하기


List of Articles
번호 제목 날짜 조회 수
23 Spring Security의 동작 방법 file 2018.06.21 4270
22 Spring source 배포 및 Tomcat Server 셋팅 2019.03.05 1346
21 [JSTL core] [c:forEach] varStatus를 활용한 변수 2019.03.05 1048
20 개발자로서 기본 구성합니다. file 2016.08.18 4939
19 공통코드관리 2016.09.21 5763
18 로그인 체크 인터셉터 사용 (AuthenticInterceptor) 2016.09.21 6678
17 서버로부터 메시지 받아서 팝업 띄우기 (1. ModelAndView 이용) file 2021.03.09 574
16 스프링 CKEditor 적용 - 에디터 2018.06.12 5580
15 스프링프레임워크 <form:form> 태그 사용법 file 2019.02.28 3516
14 스프링프레임워크 <form:form> 태그 사용법 file 2018.12.06 1182
13 예제 따라하기(1) - 기본 서블릿 구현 file 2018.06.05 2922
12 이클립스 파일 찾기 & 문자열 검색 file 2018.06.21 2407
11 이클립스(Eclipse) 소스 일괄 수정 file 2018.12.07 1097
10 이클립스(Eclipse) 한글 언어팩 설치. Babel 프로젝트 file 2018.12.07 1199
9 이클립스에서 인코딩 설정 file 2018.06.21 2330
8 전자정부 표준프레임워크 파일업로드용량설정 file 2018.12.06 1898
7 전자정부 프레임워크(egov framework) 설치하기(1) file 2017.09.12 5296
6 전자정부 프레임워크(eGovframe) 동적 웹프로젝트 시작하기(2) file 2017.09.12 4165
5 전자정부표준프레임워크 파일 업로드 크기 설정(feat. MaxUploadSizeExceededException) file 2019.02.28 1107
4 전자정부프레임워크 구조 파악하기 file 2018.06.02 4129
Board Pagination Prev 1 2 3 Next
/ 3

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved