1: …… 2: public void upload(HttpServletRequest request) throws ServletException { 3: MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request; 4: String next = (String) mRequest.getFileNames().next(); 5: MultipartFile file = mRequest.getFile(next); 6: if ( file == null ) 7: return ; 8: 9: // 업로드 파일 크기를 제한한다. 10: int size = file.getSize(); 11: if ( size > MAX_FILE_SIZE ) throw new ServletException("에러“); 12: 13: // MultipartFile로 부터 file을 얻음 14: String fileName = file.getOriginalFilename().toLowerCase(); 15: 16: // 화이트리스트 방식으로 업로드 파일의 확장자를 체크한다. 17: if ( fileName != null ) { 18: if ( fileName.endsWith(".doc") || fileName.endsWith(".hwp" ) 19: || fileName.endsWith(" .pdf") || fileName.endsWith(".xls" ) ) { 20: /* file 업로드 루틴 */ 21: } 22: else throw new ServletExeption("에러"); 23: } 24: // 업로드 파일의 디렉터리 위치는 다큐먼트 루트의 밖에 위치시킨다. 25: File uploadDir = new File("/app/webapp/data/upload/notice"); 26: String uploadFilePath = uploadDir.getAbsolutePath()+"/" + fileName; 27: 28: /* 이하 file upload 루틴 */ 29: ……