[ 라이브러리 설치 ]
:: 관련 라이브러리 jar파일을 다운로드 받아야함
1) http://www.servlets.com -> com.oreilly.servlet -> 맨 하단 cos-26Dec2008.zip 다운로드
2) 압축풀기하면 cos.jar파일이 lib폴더에 존재
3) WEB-INF 폴더의 lib폴더 내부에 cos.jar파일을 붙여넣기한 후 build해줌
[ 파일 업로드 ]
:: form 태그에 enctype을 추가해주고 input type도 file로 지정.
<form action="file.jsp" method="post" enctype="multipart/form-data"> 파일: <input type="file" name="file" /> <input type="submit" value="File Upload" /> </form> |
:: multipart/form-data를 받을 때에는 MultipartRequest객체로 받아야합니다.
:: 중복된 이름이 생기면 자동으로 이름이 변경되게 DefaultFileRenamePolicy()메서드를 호출
<% String path = request.getRealPath("fileFolder"); int size = 1024 * 1024 * 10; // 10M String file=""; String oriFile=""; // 이름이 변경되기 전의 실제 파일 이름 try { MultipartRequest multi = new MultipartRequest(request,path,size,"UTF-8", new DefaultFileRenamePolicy()); Enumeration files = multi.getFileNames(); String str = (String)files.nextElement(); file = multi.getFilesystemName(str); oriFile = multi.getOriginalFileName(str); }catch(Exception e){ e.printStackTrace(); } %> |
[ 업로드 경로 ]
:: 이클립스에 따로 폴더를 생성해서 저장하게 함
:: 실제 저장되는 경로는 workspace -> .metadata -> .plugins -> org.eclipse.wst.server.core -> tmp0 -> wtpwebapps -> 프로젝트명 -> 폴더명에 저장됨
'프로그래밍 > JSP' 카테고리의 다른 글
FrontController 패턴 & Command 패턴 (0) | 2019.04.11 |
---|---|
EL(Expression Language) (0) | 2019.03.17 |
커넥션 풀 (0) | 2019.03.13 |
DAO/DTO/PreparedStatement (0) | 2019.03.13 |
JDBC (0) | 2019.03.07 |