This may look long, but it's easy to understand--I'm just trying to give all the details you might want: In our servlet/JSP site, a user can generate a report that may or may not contain images. The servlet just sends the user to a regular HTML page. The HTML file and images it may have are stored in directories on the Tomcat server. But now we have a problem...
We're moving to 2 standalone Tomcat machines with a load balancer in front, and so now we want to move any of this stuff that was stored on the webserver into the database. If the HTML text for the report has not yet been generated for that day, I can see my web app going to the database to pull out that HTML, and if there are any images, it could pull those out of the database, but then...how does it get those to the user's web browser?
Currently, when this report loads in the browser, we do a sendRedirect to the file, and the URL displays the full path to the file (and in the HTML code, there is of course a relative link to the image file). But now, these are supposed to be pulled out of the database...are we going to have to pull them out of the database and then write them out to file on the webserver (since they might not exist on that webserver), or is there some other/better way to display them to the user?
Thanks... [ December 10, 2004: Message edited by: Stephen Huey ]
Joined: Aug 30, 2004
Inside the HTML you could do something like this
Here the SRC points to a servlet. It goes to the servlet with the appropriate details which helps the servlet retrieve the image from the database.
you can have DAOs or JDBC to access the database retrieve the BLOBs using the information provided in the query string to QUERY the database. Once you have the image BLOB retrieved from the database , you need to set the content-type of the response to the appropriate image type eg: "image/jpg" . Write the content of the blob to the response stream of the servlet....