Re: read/display image from Database using struts
Custom servlet which retrieves data from DB, writes it to the output stream. It should define correct headers first (mimeType, Expires, Date). Map it to some url like /images/* and you may pass identifiers by composing URLs like /images/myID.jpg Dariusz Wojtas On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Hi, How should I read/display image from Database...which is stored interms of bytes in the Database. Please suggest me some way to render the image in JSP. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: read/display image from Database using struts
Dear Dariusz , this is the first time for me to solve this kind of problem. could you provide some sample code to address this. thanks in advance On 12/18/06, Dariusz Wojtas [EMAIL PROTECTED] wrote: Custom servlet which retrieves data from DB, writes it to the output stream. It should define correct headers first (mimeType, Expires, Date). Map it to some url like /images/* and you may pass identifiers by composing URLs like /images/myID.jpg Dariusz Wojtas On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Hi, How should I read/display image from Database...which is stored interms of bytes in the Database. Please suggest me some way to render the image in JSP. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: read/display image from Database using struts
Hi kranti, You have to use BLOB's to store images in the DB.. Get the Out Stream from the BLOB and then write the byte[] to it.. http://wiki.apache.org/struts/StrutsFileUpload Regards, Mano -Original Message- From: Kranti [mailto:[EMAIL PROTECTED] Sent: Monday, December 18, 2006 2:21 PM To: Struts Users Mailing List Subject: read/display image from Database using struts Hi, How should I read/display image from Database...which is stored interms of bytes in the Database. Please suggest me some way to render the image in JSP. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: read/display image from Database using struts
Alternatively you could use a download action: http://wiki.apache.org/struts/StrutsFileDownload Niall On 12/18/06, Dariusz Wojtas [EMAIL PROTECTED] wrote: Custom servlet which retrieves data from DB, writes it to the output stream. It should define correct headers first (mimeType, Expires, Date). Map it to some url like /images/* and you may pass identifiers by composing URLs like /images/myID.jpg Dariusz Wojtas On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Hi, How should I read/display image from Database...which is stored interms of bytes in the Database. Please suggest me some way to render the image in JSP. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: read/display image from Database using struts
On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Dear Dariusz , this is the first time for me to solve this kind of problem. could you provide some sample code to address this. thanks in advance This is something simplified, may not compile - but exactly shows what needs to be done. Passing of blobID may be done in many ways, this way gives you chance to pass nice URLs without questionmarks, etc. Something of type /dbImg/123456.jpg /dbImg/123456.png etc. Dariusz Wojtas public class MyBlobImageServlet extends HttpServlet { public static final long EXPIRY_PERIOD = 60 * 60 * 1000; // one hour, depends on your needs @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo = request.getPathInfo(); String blobID = calculateBlobID(pathInfo); if (blobID == null) { // write some debug if needed return; } byte[] imageData = getBlobFromDB(BlobID); if (imageData == null) { // write some debug if needed return; } long lastModified = ... // depends on the logic, may be System.currentTimeMillis() // set response headers response.setContentLength(imageData.length); response.setContentType(image/png); // depends on your actual blob content, may vary response.setDateHeader(Last-Modified, lastModified); response.setDateHeader(Expires, lastModified + EXPIRY_PERIOD); // send the image to the browser try { response.getOutputStream().write(imageData); } catch (Exception e) { // write stacktrace, maybe some more info (request params, etc.) } } } web.xml Define servlet, then mapping to it. servlet servlet-nameblobImageServlet/servlet-name servlet-classmy.package.MyBlobImageServlet/servlet-class /servlet servlet-mapping servlet-nameblobImageServlet/servlet-name url-pattern/dbImg/*/url-pattern /servlet-mapping - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[OT] Re: read/display image from Database using struts
Dariusz Wojtas ha scritto: On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Dear Dariusz , this is the first time for me to solve this kind of problem. could you provide some sample code to address this. thanks in advance This is something simplified, may not compile - but exactly shows what... I feel that you made his homework Darius :-) Antonio - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT] Re: read/display image from Database using struts
Thank you very much Dariusz. I shall try this and update you. On 12/18/06, Antonio Petrelli [EMAIL PROTECTED] wrote: Dariusz Wojtas ha scritto: On 12/18/06, Kranti [EMAIL PROTECTED] wrote: Dear Dariusz , this is the first time for me to solve this kind of problem. could you provide some sample code to address this. thanks in advance This is something simplified, may not compile - but exactly shows what... I feel that you made his homework Darius :-) Antonio - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]