This is not right!

You need to write a special Java Servlet that specifically extract the image
from the database using a servlet CGI parameter.  Your , say Picture, Servlet
sends back to the browser the right content header type for the image
e.g "image/jpeg" or "image/gif".

Then code your JSPs  to refer to the servlet in the hyperlink

<img src="<%=
     request.getContextPath()+
     "/servlet/PictureSevlet?pictureID="+pictureID
     %>"   border="0" >

You can't really do this thing from a JSP because it adds extra stuff like newlines.
It has be a proper Java Servlet unfortunately.
--
Peter Pilgrim
SCJ2P

"Putting PLEASE HELP ME! URGENT HELP! in the E-Mail Subject: Line,
will probably lead to the opposite intention."             << The  Windows Trash Can >>



---------------------------------------- Message History 
----------------------------------------


From: Erwin Kodiat <[EMAIL PROTECTED]>@java.sun.com> on 01/06/2001 20:04 ZE8

Please respond to A mailing list about Java Server Pages specification and reference 
<[EMAIL PROTECTED]>

DELEGATED - Sent by:     A mailing list about Java Server Pages specification and 
[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:
Subject:  Displaying images


Dear all,
I have a BLOB field in a database which stored image in various formats
(JPG, GIF). When I try to write the file through the HTTP Response it always
fails. However, I successfully wrote it to a file so I assumed that my data
is valid (not corrupted). The followings is the scriptlet. Can anyone give
me a suggestion? Thanks a lot in advance.

Regards,

Erwin Kodiat
Mitrais Software Development Center
Bali, Indonesia

<%
try {
    BinObject bo = new BinObject();
    bo.objectID= "991986";
    bo.type="test";
    bo.contentType = "image/jpeg";
    InitialContext ic = new InitialContext();
    Object obj = ic.lookup("BinObjectBean");
    BinObjectHome home = (BinObjectHome) PortableRemoteObject.narrow(obj,
BinObjectHome.class);
    BinObjectRemote remote = home.findByPrimaryKey((PKBinObject) bo);
    BinObject objBO = remote.getRepository();
    response.setContentType("image/jpeg");

//BEGINNING OF SECTION TO DISPLAY IMAGE
    OutputStream fos = null;
    fos = response.getOutputStream();
    fos.write(objBO.binaryData, 0, objBO.binaryData.length);
    fos.flush();
    fos.close();
}
catch(Exception e) {
    System.out.println("JSP Error : "+ e.getMessage());
}
%>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to