ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 스프링 레거시 - 파일업로드 위한 세팅
    JAVA/Egov 2020. 4. 1. 12:51

    pom.xml

    		<!-- 2020.04.01 파일업로드 -->
    		<dependency>
    			<groupId>commons-fileupload</groupId>
    			<artifactId>commons-fileupload</artifactId>
    			<version>1.3.3</version>
    		</dependency>
    
    		<!-- 2020.04.01 파일업로드 -->
    		<dependency>
    			<groupId>commons-io</groupId>
    			<artifactId>commons-io</artifactId>
    			<version>2.5</version>
    		</dependency>

    MultipartFilter 적용(web.xml)

    	<!-- 멀티파트필터 -->
    	<filter>
    		<filter-name>MultipartFilter</filter-name>
     		<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>MultipartFilter</filter-name>
     		<url-pattern>/*</url-pattern>
    	</filter-mapping>

    MultipartResolver 등록 (common.xml)

    	<!-- MULTIPART RESOLVERS -->
    	<!-- regular spring resolver -->
    	<bean id="spring.RegularCommonsMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	    <property name="maxUploadSize" value="100000000" />
    	    <property name="maxInMemorySize" value="100000000" />
    	</bean>


    allowCasualMultipartParsing 설정 (context.xml)

    방법1 %TOMCAT%/conf/context.xml - Tomcat 전체 적용

    watchedResoruce는 신경 ㄴㄴ

    <Context allowCasualMultipartParsing="true">
        <!-- Default set of monitored resources. If one of these changes, the -->
    	<!-- web application will be reloaded. -->
    	<WatchedResource>WEB-INF/web.xml</WatchedResource>
    	<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    	<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    
    	<!-- Uncomment this to disable session persistence across Tomcat restarts -->
    	<!-- <Manager pathname="" /> -->
    	<!-- 캐시문제해결 -->
    	<Resources cachingAllowed="true" cacheMaxSize="100000"></Resources>
    </Context>

    form의 enctype="multipart/form-data"

    controller의 @RequestMapping(value = "/insertCompleteForProblem.do", method = RequestMethod.POST, headers = ("content-type=multipart/*"))

Designed by Tistory.