<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.0.7.RELEASE</org.springframework-version>
<org.aspectj-version>1.9.10</org.aspectj-version>
<org.slf4j-version>1.7.25</org.slf4j-version>
</properties>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<multipart-config>
<location>C:\\upload\\temp</location>
<max-file-size>20971520</max-file-size> <!-- 1MB * 20 -->
<max-request-size>41943040</max-request-size> <!-- 40MB -->
<file-size-threshold>20981520</file-size-threshold><!-- 20MB -->
</multipart-config>
<!-- 파일올리기 설정 -->
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</beans:bean>
정보: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
3월 19, 2019 9:45:43 오후 org.apache.tomcat.util.digester.Digester fatalError
심각: Parse Fatal Error at line 4 column 136: "version" 속성이 "web-app" 요소에 대해 이미 지정되었습니다.
@Controller
public class UploadController {
@GetMapping("/uploadForm")
public void uploadForm() {
System.out.println("upload form");
}
}
<form action="uploadFormAction" method="post" enctype="multipart/form-data">
<input type='file' name='uploadFile' multiple>
<button>Submit</button>
</form>
@PostMapping("/uploadFormAction")
public void uploadFormPost(MultipartFile[] uploadFile, Model model) {
String uploadFolder = "C:\\upload";
for(MultipartFile multipartFile : uploadFile) {
System.out.println("----------------------------");
System.out.println("Upload File Name:"+multipartFile.getOriginalFilename());
System.out.println("Upload File Size:"+multipartFile.getSize());
File saveFile = new File(uploadFolder, multipartFile.getOriginalFilename());
try {
multipartFile.transferTo(saveFile); // 업로드 되는 파일 저장
}catch(Exception e) {
}
}
}
<h1>Upload with Ajax</h1>
<div class='uploadDiv'>
<input type='file' name='uploadFile' multiple>
</div>
<button id='uploadBtn'>Upload</button>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha2560FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$("#uploadBtn").on("click", function(e){
var formData = new FormData();
var inputFile = $("input[name='uploadFile']");
var files = inputFile[0].files;
console.log(files);
// add filedate to formdata
for(var i = 0; i < files.length; ++i){
formData.append("uploadFile", files[i]);
}
$.ajax({
url: '/uploadAjaxAction',
processData: false,
contentType: false,
data: formData,
type: 'POST',
success: function(result){
alert("Uploaded");
}
}); // ajax
});
});
</script>
@GetMapping("/uploadAjax")
public void uploadAjax() {
System.out.println("upload ajax");
}
@PostMapping("/uploadAjaxAction")
public void uploadAjax(MultipartFile[] uploadFile) {
String uploadFolder = "C:\\upload";
for(MultipartFile multipartFile : uploadFile) {
System.out.println("----------------------------");
System.out.println("Upload File Name:"+multipartFile.getOriginalFilename());
System.out.println("Upload File Size:"+multipartFile.getSize());
File saveFile = new File(uploadFolder, multipartFile.getOriginalFilename());
try {
multipartFile.transferTo(saveFile); // 업로드 되는 파일 저장
}catch(Exception e) {
}
}
}