티스토리 뷰


pom.xml (dependency 추가)

1
2
3
4
5
6
7
8
9
10
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.1</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>
cs



dispatcher-servlet.xml (bean 추가)

1
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
cs



test.jsp (file추가 - form에 enctype 추가)

1
2
3
4
<form action="/test.do" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="서버전달"/>
</form>
cs



controller(MultipartFile)

1
2
3
4
5
6
7
8
@RequestMapping("test.do")
    public String write(MultipartFile file){
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        System.out.println(file.getContentType());
        return "";
    }
cs



반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함