Struts has a download action which can help with this:

http://wiki.apache.org/struts/StrutsFileDownload

Niall

On 7/25/06, Martin Gainty <[EMAIL PROTECTED]> wrote:
2 possibly ways
<img src with an embedded <bean:write

OR

<jsp:useBean with embedded <html:image

take a look at
http://www.velocityreviews.com/forums/t135655-help-sessions-images-amp-beans-no-cookies-please.html

Anyone else?

M-

----- Original Message -----
From: "C. Grobmeier" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Tuesday, July 25, 2006 9:55 AM
Subject: Re: Displaying images from database.


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Then how can one have an Java-Object, let's say Person.java. Person has
> a property called 'avatare' which can be get with "File getAvatar()".
> Can i do something like <bean:write name="avatar"> or so?
>
> Btw- this isn't really good practice, is it? The example below seems
> good for an Ajax request but i am not sure if i should store my images
> as a blob.
>
> chris
>
> Thomas Joseph wrote:
>> Hi Prerna,
>>
>> Use the Action Class for the image display solely for image display. When the browser executes 
the  <img src="GetImage.do?param1=blah&param2=xyz"> tag, it is basically giving a 
saparate request to your action class that generates the image.  Notice that the action class returns 
null, which means that the action class will render the response itself and will not forward to any JSP 
page.  The remaining protions of your JSP will be generated by other Action Class forwards as usual.
>>
>> Hope this helps to understand better.
>>
>> Thanks and Regards,
>> Thomas Joseph
>>
>> Kott Software Pvt. Ltd. | Vallamattom Estate | M.G.Road | Cochin-682015 | 
India
>> www.kottsoftware.com
>> 
--------------------------------------------------------------------------------
>> This email (including any attachments) is subject to copyright, the 
information in it is confidential, and it is legally privileged. Use of this email or 
of any information in it other than by the addressee is unauthorized and unlawful. If 
you are not the intended recipient of the mail, kindly intimate the author of the 
mail and delete the same.
>> 
--------------------------------------------------------------------------------
>>
>>   ----- Original Message -----
>>   From: [EMAIL PROTECTED]
>>   To: user@struts.apache.org
>>   Sent: Tuesday, July 25, 2006 6:37 PM
>>   Subject: RE: Displaying images from database.
>>
>>
>>
>>   Hi David
>>
>>   Thanks for a prompt response.
>>
>>   But I also want to display other things on the jsp page besides the
>>   image.
>>   For e.g.
>>
>>   My jsp page would have
>>
>>   Company name, Address, Business Area and its logo with an EDIT button
>>   and when the user clicks on the EDIT button he can update Address
>>   information and save the changes made
>>
>>   How can I achieve this?
>>
>>   Thanks & Regards
>>   Prerna
>>
>>   -----Original Message-----
>>   From: David Soler [mailto:[EMAIL PROTECTED]
>>   Sent: Tuesday, July 25, 2006 6:43 PM
>>   To: Struts Users Mailing List
>>   Subject: RE: Displaying images from database.
>>
>>   Try the following:
>>
>>   /******* JSP file ************/
>>
>>   <%@ taglib uri="/tags/struts-html" prefix="html" %>
>>   <html:html locale="true">
>>   <head>
>>   <html:base/>
>>   </head>
>>   <body>
>>   <%
>>   HashMap params = new HashMap();
>>   params.put("ID", request.getParameter("ID"));
>>   pageContext.setAttribute("params", params);
>>   %>
>>   <html:img page="/GetImage.do" name="params"/>
>>   </body>
>>   </html:html>
>>
>>
>>   /******* Action class *************/
>>
>>   import javax.servlet.http.HttpServletRequest;
>>   import javax.servlet.http.HttpServletResponse;
>>   import javax.servlet.http.HttpSession;
>>   import javax.servlet.*;
>>   import org.apache.struts.action.Action;
>>   import org.apache.struts.action.ActionForm;
>>   import org.apache.struts.action.ActionForward;
>>   import org.apache.struts.action.ActionMapping;
>>
>>   public class GetImageAction extends Action {
>>   public ActionForward execute(
>>   ActionMapping mapping,
>>   ActionForm form,
>>   HttpServletRequest request,
>>   HttpServletResponse response) throws Exception{
>>
>>   byte[] b;
>>
>>   //Here the code to take the image from the database (you
>>   need the parameter ID).
>>   //Put the bytes into array b[]
>>
>>   //response.setContentType("image/gif"); //it's not
>>   necessary
>>   ServletOutputStream sout = response.getOutputStream();
>>
>>   sout.write(b);
>>   sout.flush();
>>   sout.close();
>>
>>   return null;
>>   }
>>   }
>>
>>   David
>>
>>
>>
>>   -----Mensaje original-----
>>   De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>>   Enviado el: martes, 25 de julio de 2006 14:34
>>   Para: user@struts.apache.org
>>   Asunto: Displaying images from database.
>>
>>
>>   Hi All,
>>
>>
>>
>>
>>   My application saves the images in database as BLOB. I now want to
>>   display these images stored in my database. How can I do this in struts
>>   2.0 ?
>>
>>
>>
>>
>>   Thanks & Regards
>>
>>   Prerna

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to