//获得基础数据
try {
Map<String, String[]> map = request.getParameterMap ();
Route route = new Route ();
BeanUtils.populate (route,map);
//文件上传数据
Part part = request.getPart ("image");
if (part!=null &&part.getSize ()>0){//一定有数据
String submittedFileName = part.getSubmittedFileName ();
String realPath = getServletContext ().getRealPath ("/img/product/small");
System.out.println (realPath);
InputStream is = part.getInputStream ();
long l = System.currentTimeMillis ();
FileOutputStream fos = new FileOutputStream (realPath+"/"+l+submittedFileName);
IoUtil.copy (is,fos);
is.close ();
fos.close ();
route.setRimage ("img/product/small/"+l+submittedFileName);
}
route.setRdate (DateUtil.now ());
RouteServiceImpl service = new RouteServiceImpl ();
service.save (route);
response.sendRedirect (request.getContextPath ()+"/route?action=findByPage");
<form method="post" action="route" enctype="multipart/form-data">
<div class="col-md-4 data">
<input type="file" class="form-control" name="image" placeholder="上传图片" value="">
</div>