//My Controller which handles image and Data
@RequestMapping(value = "/student/edit/{id}/", method = RequestMethod.GET)
public ModelAndView editStudent( @PathVariable Integer id,
ModelMap model,
HttpServletRequest request,HttpServletResponse response) throws IOException {
Student student=studentservice.retieveStudent(id);
byte[] studentImage = student.getUserImage();
response.setContentType("image/png");
response.getOutputStream().write(studentImage);
response.getOutputStream().flush();
model.addAttribute("studentImage","studentImage")
model.addAttribute("studentName",student.getStudentName);
model.addAttribute("studentDetails",student.getStudentDetails);
return new ModelAndView("viewstudent");
}
student.jsp
<a href=student/edit/12><h1>Edit<h1></a>
viewstudent.jsp
<div>
<table> <tr><td>Student Name=${studentName}</td></tr>
<tr><td>StudentDetails=${studentDetails}</td></tr>
<img src=data:image/jpeg;base64,"<c:out value='${studentImage}'/>" alt="my image" />
</table>
当我单击链接编辑时,仅图像显示在浏览器上,viewstudent.jsp 页面未显示,如何在从 DB 获取后在 viewstudent.jsp 中显示图像以及数据