파일 업로드를 위한 HTML 설정

<form action="commons/single" method="post" encType="multipart/form-data"> 
		<input type="file" name="singlefile1" multiple><br>
		<input type="file" name="singlefile2" multiple><br>
		<input type="text" name="description1">
		<input type="text" name="description2">
		<button type="sumbit">전송</button>
	</form>

→ input 태그의 type이 file인 것이 포함되어 있는 form 태그가 submit 되어있다면 encType=”multipart/form-data” 이고 이 타입으로 넘어온 값들은 getParameter로 꺼낼 수 있음

파일 업로드를 위한 XML 설정

  1. 파일이 저장될 경로
  2. 업로드 할 파일의 최대 용량
  3. 인코딩 방식 설정(UTF-8)

→ web.xml에서 설정 후 ServletContext 객체를 불러와 사용한다.

< XML 설정 >

<context-param>
 	<param-name>upload-location</param-name>
 	<param-value>c:\\\\upload-files</param-value>
 </context-param>
 <context-param>
 	<param-name>max-file-size</param-name>
 	<param-value>10485760</param-value> <!-- 대략 1024 * 1024 * 10byte(대략 10M로 작성) -->
 </context-param>
 <context-param>
 	<param-name>encoding-type</param-name>
 	<param-value>UTF-8</param-value>
 </context-param>

< XML에서 던진 값을 Servlet에서 받아내는 과정 >

private String rootLocation;
	private int maxFileSize;
	private String encodingType;
	
	public void init() throws ServletException{
		
	ServletContext context = getServletContext();
		
	rootLocation = context.getInitParameter("upload-location");
	maxFileSize = Integer.valueOf(context.getInitParameter("max-file-size"));
	encodingType = context.getInitParameter("encoding-type");
	}

encType이 존재하며 값이 넘어왔을 때