0

Hi Iam not able to display the image in UI .In controller iam gettign the image as byte[] which is stored as BLOB in my MySQL Table. but in jsp iam not able to display the same.

My Code looks like Model Object :

class Movie { private byte[] newMovieImage; ...... }

In my controller iam getting the image as byte[] in DAO as movie Object

Movie movieInformation = movieService.getMovieInformationForUserSelection(selectedMovie,locationName);
    movieForm.setMovie(movieInformation);

In movieInformation object i have all details relating to Movie(including Image)

In 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>
Renukeswar
  • 567
  • 1
  • 6
  • 14

2 Answers2

0

You can try returning the image byte[] value as a @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.
}

Here the @RequestMapping value is the image path. So this is how you can it in the jsp.

<img src="yourControllerPath/image/1"/>
Usha
  • 1,458
  • 11
  • 13
  • Thanks for replying back. but my scenario is I have more attributes to display in the page like Movie NAme , Casting etc.. with these values i need to show up this image as well . i have only one controller which gets the movie object with all values from Database(including image).this image is coming as byte[] , this needs to be displayed in JSP . – Renukeswar Apr 24 '13 at 07:50
0

Try This (based on this post): (though it must be in the right format)

<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>
Community
  • 1
  • 1
wrm
  • 1,898
  • 13
  • 24
  • Hi Iam getting source code for image as below {movie.image} value is coming as object reference , how this can be converted to bytes again . Need help – Renukeswar Jun 17 '13 at 12:52
  • [B@44594680 is not the content. its just the java-internal descriptor... you need to write the bytes itself there instead (base64 encoded).. see fiddle on how it should look like – wrm Jun 18 '13 at 11:16