Java从数据库加载图像作为字节流并将其加载到xsl中 [英] Java load image from database as the byte stream and load it in xsl

查看:56
本文介绍了Java从数据库加载图像作为字节流并将其加载到xsl中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像作为字节流保存在数据库中,我必须在 xsl 中加载该图像.在 xsl 中是否可以从数据库加载图像?如果是这样怎么办.在 xsl 中我们以前只加载静态图像,但我需要加载动态内容

Image saved in the database as byte stream , I have to load that image in the xsl. In xsl whether loading the image from the database is possible ?? If so How it can be done. In xsl we used to load the static image only , but I need to load the dynamic content

推荐答案

让我们假设您有一个数据库,并且您正在存储可以以某种方式检索的图像.图像由一些 ID 标识......例如1234567".然后假设您的 XML 中有一些内容,例如:

Let's assume you have some database and you are storing an image that you can retrieve in some way. The image is identified by some ID ... like "1234567". Then assume your XML has something in it, like:

<imageid>1234567<imageid>

您的 XSL 将获取该信息,您可以:

You XSL would take that information and you could:

1) 创建自定义协议和 Java URL 处理程序并注册它.然后,您只需在 fo:external-graphic 的 src 属性的 URL 中使用它……例如,您创建并注册一个自定义协议getimage"和一个返回一些图像的处理程序.那么你可能有:

1) Create a custom protocol and Java URL handler and register it. Then you would merely use that in the URL for the src attribute of fo:external-graphic ... For example, you create and register a custom protocol "getimage" and a handler that returns some image. Then you might have:

<fo:external-graphic src="getimage://myserver.com/images/1234567"/>

对于代码示例,只需在网络中搜索创建您自己的 Java URL 处理程序".这是一个很好的资源:http://docstore.mik.ua/orelly/java/exp/ch09_06.htm

For code samples, just search for "Create Your Own Java URL Handlers" in the web. This is a good resource: http://docstore.mik.ua/orelly/java/exp/ch09_06.htm

2) 创建一个返回图像的 servlet,那么你可能有:

2) Create a servlet that returns the image, then you may have:

<fo:external-graphic src="http://myserver.com/getimage.jsp?image=1234567"/>

您必须决定如何从数据库中获取图像并将其流式传输回来,在标题中设置适当的信息,以便将其识别为有问题的图像类型.

You have to decide how to get the image from the database and stream it back, setting appropriate information in the headers so it is recognized as the image type in question.

这篇关于Java从数据库加载图像作为字节流并将其加载到xsl中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆