0
//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>
顯示在JSP圖像當我在鏈接編輯只圖像越做越瀏覽器和viewstudent.jsp頁面沒有得到displayd所示單擊,我如何在viewstudent.jsp一同顯示圖像與數據從DB提取後如何使用Spring MVC
您附加到「studentImage」的是一個字符串。 model.addAttribute( 「studentImage」, 「studentImage」)。 – CHowdappaM