0

I have done a lot of googling but I have not been able to find a concrete answer.

I am using Spring MVC 3 to save a user image to the database. I am now successfully able to do that. I am saving the image as a BLOB.

I can retrieve the image as a byte[].

Irregardless of file type - jpg, png, gif etc (My image upload is image file type agnostic) I would like to allow jpg and gif and png lets say to render i.e. my display technology should not be hard-coded to display just one type of image, say jpg, it should be able to display all images as they were uploaded in their respective types - that is the requirement.

NOW, I would like to do 2 things

  1. re-size the image if I have to. ie. 200 by 200
  2. render the image in a JSP WITH text. This is a user profile page so I need to have both text and image shown.

How can spring mvc render the image WITH text?

I understand from my research that you can use a BufferedImage type for the jsp? but my problem is that it seems that you can only use that if the content type is strictly image/jpeg, image/gif.

I have come across some links for resizing:
http://forum.springsource.org/archiv...p/t-46021.html

any suggestions welcome if these work BUT ultimately I need to display the image.

Please pass your thoughts along.

Thank you.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
logixplayer
  • 939
  • 2
  • 13
  • 23

1 Answers1

1

Just create a servlet which streams the image from the DB to the outputstream of the response. Then you can just call it the usual HTML way as follows:

<p>
   <img src="imageservlet/${bean.imageId}" />
   ${bean.text}
</p>

As you see, you just display the text next to the image in HTML. You cannot mix them in a single HTTP response anyway. Images counts as separate HTTP requests. For more detail and a kickoff code example of such a servlet, check this answer.

As to resizing, checkout the Java 2D API.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555