public void execute(HttpServletRequest request) throws Exception {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1*1024*1024*1024); //1 MB
/*
* Set the temporary directory to store the uploaded files of size above threshold.
*/
factory.setRepository(new File("c:\\temp"));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
InputStream uploadedStream = item.getInputStream();
try {
File f = new File("C:\\temp\\index.jpg");
item.write(f);
uploadedStream.close();
}
catch (IOException e) {
}
}
}
HTML 양식 :아파치 공용 라이브러리 파일 업로드
<form enctype="multipart/form-data" method="POST" action="<%=request.getContextPath()%>/main?cmd=ci">
<table class = "lineable">
<tr>
<td><input type="file" name="file1"/></td>
<td><input type="submit" name="q" value="import"/></td>
</tr>
</table>
</form>
내가 index.jpg을 만들 안에 저장하지만, JPG 파일로 제출 '버튼을 어떤 값을 "가져 오기"단어를 씁니다. 뭐가 잘못 되었 니. 감사. 여기
'1 * 1024 * 1024 * 1024'는'1 MB'가 아니라'1 MB'입니다. –