我有一个form bean的属性与ID,递减和imageByteArray。 Struts动作会被执行并且我想要访问这些bean的属性一样的id,递减和转换时,imageByteArray并显示为图像重定向到一个JSP。我想这post,但是,这不是为我工作。
I have a form bean with attributes id, desc and imageByteArray. Struts action gets executed and it redirects to a JSP where i want to access these bean attributes like id, desc and convert the imageByteArray and display it as an image. I tried this post, but that's not working for me.
我带code。使用Base64编码的ByteArray - 在this.bean.imageByteArray指的form bean
I encode the bytearray using Base64 - where this.bean.imageByteArray refers to the form bean
this.bean.setImageByteArray(new org.apachemons.codec.binary.Base64().encode(imageInByteArr));我想这一点,但不工作
I tried this, but not working
<img src="data:image/jpg;base64,<c:out value='${bean.imageByteArray}'/>" />字节数组(字节[] imageByteArray)是指一个base64连接codeD JPG图片,我发现了以下img标签作为输出,显然没有得到显示,
Byte array (byte[] imageByteArray) refers a base64 encoded JPG image and I'm getting the following img tag as output and obviously nothing gets displayed,
<img src="data:image/jpg;base64,[B@2e200e">不知道如何为base64字节数组,并显示转换为JSP的形象?
Any idea how to convert base64 byte array and display as an image in JSP?
推荐答案你得到的仅仅是一个数组的toString输出。但是,您需要将字节数组转换为字符串。
What you get is just the toString output of an array. You need however the byte array converted to a String.
您应该创造豆的方法
public String getByteArrayString() { return new String(this.imageByteArray); }和在你的JSP参考这一点。
and reference this in your JSP.
虽然在技术上应该定义用于进行Base64字节数组,它编码的所有字符都在标准的7位ASCII范围,这是没有必要的。
While technically you should define which encoding to use for an array of base64 bytes this is not necessary as all characters are in the standard 7bit ASCII range.
更多推荐
base64转换字节数组到一个图像
发布评论