Book book = new Book(); String serverPath = ((ServletConfig)request.getAttribute("servletConfig")) .getServletContext().getRealPath("/"); String encoding = request.getCharacterEncoding(); boolean isMulti = ServletFileUpload.isMultipartContent(request); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding(encoding); List fileItems = null; try { fileItems = upload.parseRequest(request); Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String value = null; String name = null; if (item.isFormField()) { name = item.getFieldName(); value = item.getString("utf-8"); if ("name".equals(name)) { book.setName(value); } if ("price".equals(name)) { book.setPrice(Double.parseDouble(value)); } if ("auth".equals(name)) { book.setAuth(value); } if ("desc".equals(name)) { book.setDesc(value); } if ("publisher".equals(name)) { book.setPublisher(value); } if ("typeid".equals(name)) { book.setType(new BookTypeDao().selectTypeById(Integer.parseInt(value))); } if ("publisher".equals(name)) { book.setPublisher(value); } } else { String appPath = request.getContextPath(); System.out.println(appPath); String imgurl = item.getName(); System.out.println(imgurl); System.out.println(serverPath + "/uploads/" + imgurl); File uploadFile = new File(serverPath + "/uploads/" + imgurl); book.setImgurl(imgurl); item.write(uploadFile); } } } catch (FileUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } BookDao bookDao = new BookDao(); if(bookDao.addBook(book)){ return "/Controller/AdminShowBookList.do"; } <form action="${ctx}/Controller/AdminAddBook.do" method="post" enctype="multipart/form-data"> 书籍名称:<input type="text" name="name" /><br/> 作者:<input type="text" name="auth" /><br/> 出版社:<input type="text" name="publisher" /><br/> 价格:<input type="text" name="price" /><br/> 图书类别: <select name="typeid"> <c:forEach items="${typeList}" var="type"> <option value="${type.id }">${type.name }</option> </c:forEach> </select><br/> 书籍描述:<br/><textarea name="desc" rows="6" cols="50"> 图片: 图片: