ok below is the code for the GetUserImage servlet which connects to the OID and pipes the retrieved image to the ServletOutputStream (the LDAP retrieval is very specific to Oracles Internet Directory but your directory should have a corrosponding Java API)
package com.sbec.cco; import javax.servlet.*; import javax.servlet.http.*; import java.io.PrintWriter; import java.io.IOException; import javax.naming.*; import oracle.ldap.util.*; import oracle.ldap.util.jndi.*; import java.io.*; import java.util.*; import javax.naming.*; import javax.naming.directory.*; public class GetUserImage extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=windows-1252"; public void init(ServletConfig config) throws ServletException { super.init(config); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //set the content type of the output to let the browser know a jpg image is coming response.setContentType("image/jpeg"); //ID of the users image to retrive String userId = request.getParameter("userId"); byte bt[] = null; //get the OutputStream to send the image back to the browser OutputStream ot = response.getOutputStream(); try { // make connection to LDAP and lookup user InitialDirContext ctx = ConnectionUtil.getDefaultDirCtx("orpsweb1","389","cn=oidadmin","somepassword "); Subscriber mysub = new Subscriber(ctx,Util.IDTYPE_DN,"dc=com",false); User me = new User(ctx,Util.IDTYPE_SIMPLE,userId,mysub,false); String[] ussrAttrList = {"jpegPhoto"}; // get the jpegPhoto attribute of this users entry (getValue returns an Object which I cast to byte[]) bt = (byte[])((me.getProperties(ctx,ussrAttrList)).getPropertySet(0)).getProperty ("jpegPhoto").getValue(0); //write the byte[] to the OutputStream ot.write(bt); //close OutputStream and we're done ot.close(); } catch (Exception sqle) { } } } Now say I have a jsp page which lists a LDAP users entries and I want to show the image contained in the directory I place the following in the spot I want the image to appear <img src="/ldap/getuserimage?userId=<%=userId%>"> -----Original Message----- From: Roland Dong [mailto:rdong@;CAIT.ORG] Sent: Thursday, October 24, 2002 12:30 PM To: [EMAIL PROTECTED] Subject: Re: How to retrieve jpeg image file from LDAP? Not sure if You have received my previous message. Just wondering if you could forward the GetImage servelt code. That would be a great help. I have been searching for a solution for a few days! Thanks a million, Roland On 10/22/02 7:36 PM, "Nimmons, Buster" <[EMAIL PROTECTED]> wrote: > As far as the first question it depends on the LDAP directory. We use Oracle > Internet Directory which has a great Java API for accessing the Directory. > > > as far as displaying an image once it's recieved I wrote a servlet called > GetImage which connects to the LDAP Directory and retrieves the image then > simply sets the return type of the output stream to "image/jpg" and pipes > output of the image retrieval to the servlets output stream. Any HTML or jsp > page which needs an image from the Directory uses the following code > > <img src="/getImage?fileName=SomeName"> thus instead of the image src making > a direct link to the image it calls the servlet which gets the image and > outputs it in the correct format. > > -----Original Message----- > From: Roland Dong [mailto:rdong@;CAIT.ORG] > Sent: Tuesday, October 22, 2002 3:54 PM > To: [EMAIL PROTECTED] > Subject: How to retrieve jpeg image file from LDAP? > > > I am working on a project which retrieves jpeg image files and heave them > displayed in the browser. > > These jpeg photos are stored as base64 in LDAP server. > I am using JSP for this project. > > My questions are > > 1. How do I retrieve images from LDAP using jsp? I know how to retrieve any > data of string type. > 2. How do I decode them back into binary and display them? > > Any examples? > > > Thanks a lot > > RD > > =========================================================================== > 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://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com > > =========================================================================== > 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://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com =========================================================================== 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://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com =========================================================================== 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://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com