无法在UI中使用Spring MVC 3.0显示图像
嗨Iam无法在UI中显示图像。在控制器iam中将图像存储为字节[],并将其作为BLOB存储在我的MySQL表中。但在jsp iam中无法显示相同的内容。无法在UI中使用Spring MVC 3.0显示图像
我的代码看起来像 模型对象:
类电影{ 私人字节[] newMovieImage; ...... }
以我控制器IAM获得的图像作为字节[]在DAO作为电影目标
Movie movieInformation = movieService.getMovieInformationForUserSelection(selectedMovie,locationName);
movieForm.setMovie(movieInformation);
在movieInformation目标i具有关于电影的所有细节(包括图像)
在JSP中:
<form:form modelAttribute="movieForm" id="movieForm" name="movieForm">
<div class="ticket_mov_review_rev">
<a href="booking.html"> <img src="<c:url value="${movieForm.newImage}"></c:url>" /></a>
<div class="ticket_mov_review_rev_one">
<br /><br />
<p><b>Censor certificate </b>
</p>
<p><b>Movie Name</b><span style="color:#00F;">
<c:out value="${movieForm.movie.movieName}"></c:out>
<p><b>Casting</b>
<c:out value="${movieForm.movie.casting}"></c:out>
<p><b>Direction</b>
您可以尝试返回图像的byte []值作为@ResponseBody
,
@RequestMapping(method = RequestMethod.GET, value = "/image/{id}")
@ResponseBody
public byte[] getImage(@PathVariable("id") int imageId) {
// Get the image based on the id
// return the image byte[] value.
}
这里的@RequestMapping
值是图像路径。所以这就是你在jsp中的方式。
<img src="yourControllerPath/image/1"/>
感谢回答回来。但我的情况是我有更多的属性来显示在电影NAME,铸造等页面。与这些值我需要显示此图像以及。我只有一个控制器,它使用来自数据库(包括图像)的所有值获取电影对象。该图像即将以字节[]形式出现,这需要在JSP中显示。 – Renukeswar 2013-04-24 07:50:56
试试这个(基于this post):(尽管它必须是正确的格式)
<form:form modelAttribute="movieForm" id="movieForm" name="movieForm">
<div class="ticket_mov_review_rev">
<a href="booking.html"> <img src="data:image/jpeg;base64,${movieForm.newImage}" /></a>
<div class="ticket_mov_review_rev_one">
<br /><br />
<p><b>Censor certificate </b>
</p>
<p><b>Movie Name</b><span style="color:#00F;">
<c:out value="${movieForm.movie.movieName}"></c:out>
<p><b>Casting</b>
<c:out value="${movieForm.movie.casting}"></c:out>
<p><b>Direction</b>
嗨感谢回复,但它没有为我工作 – Renukeswar 2013-04-25 01:06:47
这应该工作,如果您使用JPG格式:http://jsfiddle.net/MgZnV/ – wrm 2013-04-25 08:10:57
嗨Iam获取图像的源代码如下 {movie.image}值是作为对象引用而来的,它如何再次转换为字节。需要帮助 – Renukeswar 2013-06-17 12:52:35
请一些格式添加到您的代码 – 2013-04-23 14:50:28