日期:2014-05-17 浏览次数:20721 次
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException:
the request was rejected because its size (3603280) exceeds the configured maximum (2097152)
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.commons.fileupload.*"%>
<%@page import="org.apache.commons.fileupload.servlet.*"%>
<%@page import="org.apache.commons.fileupload.disk.*"%>
<%
String path = getServletContext().getRealPath("");
if (ServletFileUpload.isMultipartContent(request)) {
// ファクトリー生成
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1426);
factory.setRepository(new File(path+"/music")); //一時的に保存する際のディレクトリ
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(10000 * 1024);
upload.setFileSizeMax(10000 * 1024);
List<FileItem> items;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
// エラー処理
throw new ServletException(e);
}
// 全フィールドに対するループ
for (Object val : items) {
FileItem item = (FileItem) val;
if (item.isFormField()) {
// type="file"以外のフィールド
out.println(item.getFieldName());
} else {
// type="file"のフィールド
File f = new File(item.getName());
try {
item.write(new File(path+"/music", f.getName()));
out.println(f.getName());
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
}
}
%>