controller
@RequestMapping(value = "imagefetch", method = RequestMethod.GET)
@ResponseBody
public void displayimage(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response) {
ServletOutputStream out;
try {
response.setContentType("image/jpeg");
out = response.getOutputStream();
FileInputStream fin = new FileInputStream("/home/vpatel/Desktop/image/" + filename);
BufferedInputStream bin = new BufferedInputStream(fin);
BufferedOutputStream bout = new BufferedOutputStream(out);
int ch = 0;
while ((ch = bin.read()) != -1) {
bout.write(ch);
}
bin.close();
fin.close();
bout.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
display
<c:forEach items="${user}" var="x">
<tr>
<td>${x.userid}</td>
<td>${x.usertype}</td>
<td><img src="imagefetch?filename=${x.profileimg}"
height="50px" widtd="50px" /></td>
<td><a href="delete?userid=${x.userid}">Delete</a></td>
<td><a href="update?userid=${x.userid}">Update</a></td>
<td><a href="qualification/home?userid=${x.userid}">Edit
Qualification</a></td>
<td><a
href="qualification/showqualification?userid=${x.userid}">View
Qualification</a></td>
</tr>
</c:forEach>
dao
public String getOldFilename(int userid) {
String sql = " SELECT profileimg from user_details where userid=" + userid;
String profileimg = template.queryForObject(sql, String.class);
return profileimg;
}
@RequestMapping(value = "imagefetch", method = RequestMethod.GET)
@ResponseBody
public void displayimage(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response) {
ServletOutputStream out;
try {
response.setContentType("image/jpeg");
out = response.getOutputStream();
FileInputStream fin = new FileInputStream("/home/vpatel/Desktop/image/" + filename);
BufferedInputStream bin = new BufferedInputStream(fin);
BufferedOutputStream bout = new BufferedOutputStream(out);
int ch = 0;
while ((ch = bin.read()) != -1) {
bout.write(ch);
}
bin.close();
fin.close();
bout.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
display
<c:forEach items="${user}" var="x">
<tr>
<td>${x.userid}</td>
<td>${x.usertype}</td>
<td><img src="imagefetch?filename=${x.profileimg}"
height="50px" widtd="50px" /></td>
<td><a href="delete?userid=${x.userid}">Delete</a></td>
<td><a href="update?userid=${x.userid}">Update</a></td>
<td><a href="qualification/home?userid=${x.userid}">Edit
Qualification</a></td>
<td><a
href="qualification/showqualification?userid=${x.userid}">View
Qualification</a></td>
</tr>
</c:forEach>
dao
public String getOldFilename(int userid) {
String sql = " SELECT profileimg from user_details where userid=" + userid;
String profileimg = template.queryForObject(sql, String.class);
return profileimg;
}