日期:2014-05-17 浏览次数:20827 次
DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try{
fileList = upload.parseRequest(request);
}catch(FileUploadException ex){
return;
}
Iterator<FileItem> it = fileList.iterator();
while(it.hasNext()){
FileItem item = it.next();
if(!item.isFormField()){
try{
InputStream in = item.getInputStream();
int length = (int)item.getSize();
byte[] b = new byte[length];
in.read(b, 0, length);
insert into table(id,image)values(1,b);
}catch(Exception e){
e.printStackTrace();
}