为什么 JSTL 在图像 blob 数据的空检查中返回误报?
以下两个 JSTL 检查都返回正值 - 导致显示内部消息(“图像不为空”/“图像不为空”) - 即使当前记录没有与之关联的图像。
<c:if test="${rec.imgdata != null}">image not null</c:if>
<c:if test="${not empty rec.imgdata}">image not empty</c:if>
每个记录的图像都存储为 Blob。检查 Blob (rec.imgdata
) 是否非空的正确方法是什么?
Both of the following JSTL checks return positive - resulting in the inner message being displayed ("image not null"/"image not empty") - even when the current record does not have an image associated with it.
<c:if test="${rec.imgdata != null}">image not null</c:if>
<c:if test="${not empty rec.imgdata}">image not empty</c:if>
The image is stored as a Blob for each record. What's the correct way to check whether the Blob (rec.imgdata
) is non-empty?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会在 JSTL 中使用
Blob
。我会预先通过调用 length() 来验证 blob 是否不为空,然后将该值设置为请求属性。即:如果您有多个
rec
,则创建一个新属性imageAvailable
并调用rec.setImageAvailable(rec.getImgData().length() > 0 )
请记住,您无法在一个响应中流式传输页面和图像。您只需设置图像的路径。这将是一个新的 servlet,它将依次加载
Blob
并将其流式传输到客户端。I wouldn't use
Blob
in JSTL. I'd verify beforehand whether the blob is not empty by callinglength()
, and then set the value as request attribute. I.e.:if you have more than one
rec
then create a new propertyimageAvailable
and callrec.setImageAvailable(rec.getImgData().length() > 0)
Have in mind that you can't stream the page AND the image in one response. You only set the path to the image. Which will be a new servlet which will in turn load thh
Blob
and stream it to the client.