【问题标题】:How to display multiple byte array images in the HTML如何在 HTML 中显示多字节数组图像
【发布时间】:2013-03-08 06:57:23
【问题描述】:

我有一个字节数组图像列表。

我正在 HTML 页面中显示图像。 如果我想显示 25 个这样的图像,我必须访问数据库 25 次。

我想避免这种情况,请帮忙。

HTML 代码

myProfile.init(function (map) {
    dom.byId("Image").src="UserImageDisplay?&userId="+map["userId"];    
}

Java 代码

byte[] image = userSession.getPhoto(Integer.parseInt(request.getParameter("userId"));

response.setContentType("image/imagetype");

OutputStream out = response.getOutputStream();

out.write(image);
out.flush();
out.close();

【问题讨论】:

    标签: html jsp servlets bytearray


    【解决方案1】:

    嗯,你已经从某个地方获得了图像,无论是数据库还是文件服务器。

    既然你已经建议了,你不想每次都从数据库加载它。

    这就是我会做些什么来提高性能。

    1) Cache your images 每当您从数据库中获取一个(缓存中不可用)时。 2)The cache can be Server Memory(强烈建议不要这样做,因为你会很快耗尽内存),or cache the images in local storage

    3) Storing of images in the cache ,可以是 done realtime 即当从 Web 应用程序请求文件时,或 you could schedule a cron/batch job 提前这样做。最好在非高峰时段。

    3 and 4 depends on how frequent the images are updated in the Database 之间进行选择。我会留给你的。

    4) 你可以明确地specify the browser to cache the images。你可以用 tag

    【讨论】:

      【解决方案2】:

      我认为你应该缓存你的图片。

      最好是启动一个生成图像文件的 cron 作业。

      【讨论】:

        猜你喜欢
        • 2014-01-12
        • 2010-12-18
        • 2021-04-12
        • 1970-01-01
        • 2013-05-18
        • 2013-07-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多