img src 加载图片实现方法 博客分类: web前端
程序员文章站
2024-03-22 15:44:04
...
<img id="bac100" width="110px" height="140px"
src="${rootPath}/insurcardheavycard/ShowPersonPhotoAction.action?aac001=${checkedFailePersonDTO.id}">
这个是jsp页面显示的一个例子,可以显示多张图片。其中src= "${rootPath}/insurcardheavycard/ShowPersonPhotoAction.action?aac001=${checkedFailePersonDTO.id}" 指向action,传入参数checkedFailePersonDTO.id唯一标识出是哪一张图片
后台获取到对应的流后:可以通过下面方法输出到输出流中
private void outputPicture(HttpServletResponse res, InputStream inputStream)
throws IOException {
if (inputStream == null) {
return;
}
OutputStream out = res.getOutputStream();
byte[] buff = new byte[1024];
int length = 0;
while ((length = inputStream.read(buff)) > 0) {
out.write(buff, 0, length);
}
out.flush();
out.close();
}
src="${rootPath}/insurcardheavycard/ShowPersonPhotoAction.action?aac001=${checkedFailePersonDTO.id}">
这个是jsp页面显示的一个例子,可以显示多张图片。其中src= "${rootPath}/insurcardheavycard/ShowPersonPhotoAction.action?aac001=${checkedFailePersonDTO.id}" 指向action,传入参数checkedFailePersonDTO.id唯一标识出是哪一张图片
后台获取到对应的流后:可以通过下面方法输出到输出流中
private void outputPicture(HttpServletResponse res, InputStream inputStream)
throws IOException {
if (inputStream == null) {
return;
}
OutputStream out = res.getOutputStream();
byte[] buff = new byte[1024];
int length = 0;
while ((length = inputStream.read(buff)) > 0) {
out.write(buff, 0, length);
}
out.flush();
out.close();
}