https://purple-j.tistory.com/212
파일 업로드를 위한 설정
- spring web mvc 제작중 - sts4 - tomcat 9 - jdk 1.8 1. servlet-context.xml 설정 아래단 src > main > webapp > WEB-INF > spring > servlet-context.xml에 아래 코드를 넣어준다 class="org.springframework..
purple-j.tistory.com
https://purple-j.tistory.com/214
다중 파일을 받아오기 위한 설정 / 파일 3탄
https://purple-j.tistory.com/213 webapp > WEB-INF > spring > servlet-context.xml에 아래 코드를 넣어준다 class="org.springframework.." data-og-host="purple-j.tistory.com" data-og-source-url="h.." dat..
purple-j.tistory.com
이전에 포스팅한 글과 이어지는 파일 설정 2탄
1. 파일 저장을 원하는 경로에 폴더 생성 ex) webapp > static > upload 폴더 만듬
2. 해당 파라미터 값을 받는 Controller 설정
1) 해당 함수 내에서만 사용되는 경우
HttpServletRequest requset로 파라미터를 받아와서 ServletContext ctx = request.getServletContext()로 경로를 알아낸다
webPath : 위에서 만들어 둔 파일 저장 폴더영역
realPath : 배포시 저장되는 실제 파일의 경로 ctx.getRealPath()로 받아와준다
최종 파일 저장을 위한 코드 :
File savaFile = new File(realPath);
file.transferTo(savaFile);
2) 전역적으로 사용되는 경우 : 전역변수로 설정
함수 내의 ServletContext ctx = request.getServletContext(); 부분을 삭제하고
class 내부 상단에 직접적으로 선언
'프로그래밍 > spring' 카테고리의 다른 글
코드로 배우는 스프링 웹 프로젝트 1 _ STS3 Lagacy Project 개발 환경 구축 (0) | 2022.02.04 |
---|---|
다중 파일을 받아오기 위한 설정 / 파일 3탄 (0) | 2022.02.03 |
단일 파일 업로드를 위한 설정 / 파일 1탄 (0) | 2022.02.03 |
전송 시 한글 입력이 깨지는 문제 (0) | 2022.02.03 |
톰캣 Tomcat 구버전 다운로드 (0) | 2022.01.04 |