Massimo Casella writes:
> I have an image stored in a field of my database. I must show this image
in
> a html page on Apache server.
> Can I show the images without write before the file in the server
> filesistem?
Sure -- you can write a servlet which retrieves the image from the database
and streams the image directly from the database back to the client,
something
like this:
ResultSet rs = stmt.executeQuery("select image from images where blah
blah");
if (rs.next()) {
response.setContentType("image/gif");
InputStream is = rs.getBinaryStream(1);
OutputStream os = response.getOutputStream();
byte[] buf = new byte[4096];
int cnt;
while ((cnt = is.read(buf)) > 0) os.write(buf, 0, cnt);
}
Of course, you probably also want to handle Content-Length, not found,
exceptions, etc.
(The latest release of the Quadcap Embeddable Database, 1.0b14, contains
a sample application, including source code, for an image database, which
includes an ImageServlet that does the above, as well as a JSP-based
user interface to the image database. You can download it from the Quadcap
website at http://www.quadcap.com/home.html)
Stan Bailes
Quadcap Software
http://www.quadcap.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html