ServletAdd添加中添加图片的代码:
@MultipartConfig @WebServlet("/ServletAdd") public class ServletAdd extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 防乱码 request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); // Service层中调用 FimlService fimlService=new FimlService(); // 使用Map集合为添加做准备 Map<String, String[]> map = request.getParameterMap(); Fiml fiml=new Fiml(); try { // 使用 BeanUtils.populate工具将实体类存入Map集合 BeanUtils.populate(fiml,map); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } fiml.setDname(null); // 获取上传的文件路径 String path = getServletContext().getRealPath