简体   繁体   English

如何从MySQL Db在struts2中显示图像的斑点类型

[英]how to display blob type of image in struts2 from Mysql Db

Blob type of image is reaching JSP page but it is in an unreadable format. 图像的Blob类型正在到达JSP页面,但格式不可读。

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: 最后是我的JSP页面:

<img src="<s:property value="repCurrentImage"/>

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). 看起来您正在尝试将图像的内容直接嵌入到JSP中...这将无法工作,您只能提供一个url(最好使用struts2 url标记构造,该URL会引用将返回流结果的操作并采用所需的参数来选择您的图片)。

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 这个问题/答案显示了具有这样一种结果类型的操作,该操作用于渲染图片: 如何使用Hibernate从Struts 2中的mySql DB在jsp页面中显示图像(bolb类型)

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!). 我的经验是,一个好的DB数据类型是MEDIUMBLOB,图像的任何较小的截断都成为一个问题(您将只看到文件的第一部分,因为这可以存储的所有内容,尽管它可能在生产中是最好的)。确保文件适合!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM