【发布时间】:2015-06-04 19:36:13
【问题描述】:
UserEntityManager.java
@RequestMapping(value = "getImages.do", method = RequestMethod.GET)
public byte[] getImage(final String username) {
Blob img = null;
byte[] imgData = null;
sql = "SELECT UserPhoto FROM u_logininfo WHERE LoginName = ?";
try {
img = jdbcTemplate.queryForObject(sql, new Object[]{username}, new RowMapper<Blob>() {
@Override
public Blob mapRow(ResultSet rs, int arg1)
throws SQLException {
Blob blob = rs.getBlob("UserPhoto");
return blob;
}
});
imgData = img.getBytes(1, (int) img.length());
return imgData;
//File file = new File
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
这是我的控制器
UserController.java
@RequestMapping(value = "getImages.do" , method = RequestMethod.GET)
private ModelAndView viewImages(Model model){
String userName = (String)SecurityContextHolder.getContext().getAuthentication().getName();
byte[] image = userEntityManager.getImage(userName);
model.addAttribute("images", image);
return new ModelAndView("Fun Zone/Photo");
}
和jsp
<div class="col-sm-2" style="margin-top: 288px; margin-left: 291px;">
<img src="getImages.do">
</div>
我想使用 Spring MVC 3 在 .jsp 页面上显示图像,但图像在 jsp 中不显示。
【问题讨论】:
-
你能检查浏览器控制台,它给出了什么错误?
-
localhost:8081/demo/getImages.do 方法调用并且控制台中没有显示任何错误
-
为什么 UserEntityManager 有这样的请求映射? @RequestMapping(value = "getImages.do", method = RequestMethod.GET) 就可以了吗?这是服务还是 DAO 对吧?
标签: java html spring jsp spring-mvc