본문 바로가기
홈페이지 만들기/Spring

스프링 파일 업로드

by 리틀홍콩 2015. 4. 16.
728x90

프레젠테이션 레이어 서블릿 관리하는 xml에서

(나의 경우 WEB-INF/config/presentation-layer.xml)에 위치시켯다. 위치는 http://tlstjscjswo.tistory.com/entry/스프링-다국어처리 참조하길 바란다.)

 

==== presentation-layer.xml ===============================================

...

...

...

 

 <!-- 파일 업로드 설정 -->
 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <property name="maxUploadSize" value="1000000" />
 </bean>

 

...

...

=========================================================================

** 저 설정이 없다면 파일 업로드가 되지 않는다.

 

=== BoardVO.java (Value Object) - POJO데이터를 담는 자바 ================

 

public class BoardVO {
 private int seq;
 private String title;
 private String writer;
 private String content;
 private Date regDate;
 private int cnt;
 private String searchCondition;
 private String searchKeyword;
 private MultipartFile uploadFile;
 
 public MultipartFile getUploadFile() {
  return uploadFile;
 }
 public void setUploadFile(MultipartFile uploadFile) {
  this.uploadFile = uploadFile;
 }
 public String getSearchCondition() {
  return searchCondition;
 }
 public void setSearchCondition(String searchCondition) {
  this.searchCondition = searchCondition;
 }

..

..

=========================================================================

 

=== boardController.java ==================================================

 

...

...

  MultipartFile uploadFile = vo.getUploadFile();
  if(uploadFile.getOriginalFilename().length() > 0) {
   String fileName = uploadFile.getOriginalFilename();
   byte[] data = uploadFile.getBytes();
   FileOutputStream out = new FileOutputStream("C:/DEV/workspace/SpringMVC2Project/WebContent/WEB-INF/uploadFiles/"+fileName);
   out.write(data);
   out.close();
  }

...

 

=========================================================================

 

'홈페이지 만들기 > Spring' 카테고리의 다른 글

iBatis 연동  (0) 2015.04.17
스프링 다국어처리  (0) 2015.04.16
스프링 ViewResolver  (0) 2015.04.15
스프링 action-servlet 위치 및 파일명 변경  (0) 2015.04.15
스프링 한글 인코딩으로 만들기  (0) 2015.04.15

댓글