I know I can get an image from a database and render it to a web page
using a separate servlet. I don't particularly want to do this. I was
thinking that it might be possible to write a Click control to stuff
the byte into an Image and set the response content type to
"image/gif" or whatever in the toString() method.
I'm not sure this would work, as the response stream would likely already be set by whatever Page is being rendered.
Likely what one would have to do is subclass ClickServlet and override
handleRequest (or processPage()) and interrogate the URL to determine
whether the request was for an actual page or an image, then delegate
rendering of the response for images to the Control, while skipping
"normal" Page processing -- all in all a pretty messy solution.
I don't want to unnecessarily belabor this point, but is this in an
effort to potentially migrate a legacy application? The reason I
ask is, in general, unless it's a low volume site, serving images up
dynamically from the database isn't really a good thing -- having large
byte arrays floating around in memory can increase consumption, and
dynamic images reduce the opportunity for server and browser
caching. There are probably other approaches that could also be
researched, however (temporary directories to write out images
statically, then serve them up normally for instance).
I know I can get an image from a database and render it to a web page using a separate servlet. I don't particularly want to do this. I was thinking that it might be possible to write a Click control to stuff
the byte into an Image and set the response content type to "image/gif" or whatever in the toString() method.
The application has billions of small images in a database - each image if
little more than 2k in size. It is impractical to have all these images on the
file system. There are a lot of them. Billions. Although the user is only
looking at one at a time...
Anyway, I have found a solution, albeit a bit clunky for now, so it needs
tidying up. The solution entailed creating a ImageView.htm and associated
ImageView.java, subclassed off Page. I override getContentType, and in onGet I
stream the byte from the database into the response ServletOutputStream.
Standard stuff. Then, in my ImageView.htm, I have <img src='ImageView.htm'>, and
in the component that wants to display the image, I #parse('ImageView.htm').
Very clunky for now, and there is some domain-specific code in there and I am
passing stuff around in the session. I want to tidy this up and make it a bit
more resusable/parameter driven, at which point it's coming your way :-)