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




The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments.


WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.


www.wipro.com

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

Reply via email to