webtest/pdsTest/upLoadTest.jsp
[소스]
[ 결과 ]
자료실 기초 설계 -> 내가 원하는 확장자 , 원하는 크기로 만 업로드 가능하게 설정
upLoadTest.jsp
10번 라인
뒤에서 부터 3자리 추출 test.txt -> txt 추출 [ 즉 3자리 확장자만 사용하겠다는 의미 ]
마지막점을 기준으로 추출 해서 변수에 담는 방법도 있다. [모든 확장자 사용시 ]
11번 라인
ext.toUpperCase() 확장자를 대문자로 치환해서 변수 uExt 에 담는다. 대문자로 비교하기 위해
13번 라인
//업로드할 파일의 사이즈 구함 ("file"). files 는 메소드
42번 라인에 아이디 이름을 써주면 된다.
최대 10 MB 까지 허용하겠다. [1024*1024 = 1MB]
ZIP 파일이 아니거나 JPG 가 아니거나 TXT 가 아니거나 HWP가 아니면
[업로드 기능파일 'zip jpg txt hwp 만 가능합니다 '] 메시지 출력
업로드 전이면 [업로드 파일 선택하세요 ] 메시지 출력
파일명 공백 처리 indexOf 는 문자를 찾을수 없을때 -1 을 반환
문자을 찾을 수 없을 때 -1을 반환
즉 (fname.indexOf(" ") != -1)
[공백]를 찾지못한게 아니면 == 즉 공백을 찾았으면
파일사이즈 > 설정한최대크기 [10MB]
enctype ="Multipart/form-data"
[Multipart/form-data 서버에 파일을 전송할때 쓰는 타입 모든라이브러리는 파일업로드시 꼭적어야함]
<input type ="file" name="file" id="file"/>
type = file 은 파일 업로드 속성
실행화면
Upload Test
test.txt 파일을 업로드 했을때
'Web > Spring , Springboot , JPA' 카테고리의 다른 글
파일 자료실 - 개념 설명 (0) | 2020.05.20 |
---|---|
파일자료실 - upLoadTestOk.jsp (0) | 2020.05.20 |
Servlet 선처리, 후처리 @PostConstruct , @PreDestroy (0) | 2020.05.19 |
서블릿 - 라이프사이클(생명주기) Test (0) | 2020.05.19 |
[jsp]web.xml 만드는방법 (0) | 2020.04.19 |