java-图片上传

图片上传 后台代码

public String insertStudent(Student student,HttpServletRequest request,
@RequestParam(“file”) MultipartFile flie) throws IllegalStateException, IOException {
//选择图片路径
String path = request.getServletContext().getRealPath("/images");
String flog = upload.upimg(path, flie);
String img = flie.getOriginalFilename();
//获取图片字段
student.setImg(img);
//添加信息
studentMapper.insertStudent(student);
//添加成功跳转列表页面
return “redirect:studentList”;
}

图片上传前台注意事项

首先在 webapp下面建立images文件夹用于存放上传的图片

图片显示格式java-图片上传

上传图片 提交form表单

java-图片上传

最终大boss util包
上传图片的工具类
java-图片上传