0

Blob type of image is reaching JSP page but it is in an unreadable format.

Service Method:

Iterator itr = list.iterator();
if (itr.hasNext()) {
     Membersdetails get = (Membersdetails) itr.next();
     repCurrentImage = get.getRepPicture();
}
return repCurrentImage;

& my Action Class:

repCurrentImage = sdf.getrepImage(loginId);

Finally My JSP page:

<img src="<s:property value="repCurrentImage"/>
4
  • How do u want to display the image. In a table or you want to render it on the page. Commented Apr 26, 2012 at 7:49
  • Storing files in database is bad design. I would suggest to store the file-name or file-id in database and pick the file from file-system only. Commented Apr 26, 2012 at 9:32
  • @tusar how so? The bench marks I've seen show marginal performance difference and it avoids some platform specific issues with how containers each manage file systems. Commented Apr 26, 2012 at 9:50
  • @ Uchenna I want to show it in table tag using image tag Commented Apr 26, 2012 at 12:32

1 Answer 1

1

It looks like you are trying to embed the content of the image directly into the JSP... this will not work you can only supply a url (best constructed with the struts2 url tag, which will reference the action which will return a stream result and take the required parameters to select your image).

This question/answer shows an action with such a result type which is used to render a picture: How to display image(bolb type) in jsp page from mySql DB in Struts 2 using Hibernate

I'm my experience a good DB datatype is MEDIUMBLOB, with anything smaller truncation of the image became an issue (You will just see the first part of the file because that is all that can be stored although it would probably be best in production to make sure the file fits!).

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for the nice example link @Quaternion sir. And regarding my comments about bad design, I didn't think of cross-platform dependency. Thanks for clearing. Actually I have this perception that file-systems will always be faster than database while storing and retrieving files.
new code: if (itr.hasNext()) { Membersdetails get = (Membersdetails) itr.next(); repCurrentSignature = get.getRepSignature(); HttpServletResponse res = ServletActionContext.getResponse(); res.setContentType("multipart/form-data"); ServletOutputStream out = res.getOutputStream(); out.write(repCurrentSignature); out.flush(); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.