问题
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
回答1:
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>
You XSL would take that information and you could:
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"/>
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) 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.
来源:https://stackoverflow.com/questions/24347812/java-load-image-from-database-as-the-byte-stream-and-load-it-in-xsl