Yes I have.  The following JSP executes quite well.  The problem I have is
converting the Byte array to a BufferedImage.  Pls help Alan.  I have
searched google and I'm still searching. I have   Jason Hunter's book and
also Marty Hall's book.

<%@ page import = "com.sybase.jaguar.jcm.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "com.sun.image.codec.jpeg.*" %>
<%@ page import = "java.awt.image.*" %>
<%@ page import = "java.awt.*" %>

<%
        final int WIDTH = 150;
    final int HEIGHT = 150;
        String contentype = null;
        contentype = request.getParameter("ctype");
        if (contentype != null){
                response.setContentType("image/jpeg");
                String sql = "select photo_data from images where employee_number =
'92004'";

                JCMCache cache = JCM.getCacheByName("SelfServiceDB");
                Connection conn = cache.getConnection(JCMCache.JCM_WAIT);
                Statement stmt = conn.createStatement();
                java.io.OutputStream cout = response.getOutputStream();
                ResultSet resultSet = stmt.executeQuery( sql );

                while (resultSet.next()){
                        // byte[] bytearray = resultSet.getString(1).getBytes());
                }
                //cout.close();
                // create a blank image
        BufferedImage image = new
BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.setColor(Color.yellow);
        g2.fillRect(0,0,WIDTH,HEIGHT);

        // encode the output to JPEG
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(cout);
        encoder.encode(image);

                cout.flush();
        cout.close();
    } else {
      out.println("<html>");
      out.println("  <head>");
      out.println("    <title>Photo</title>");
      out.println("  </head>");
      out.println("  <body>");
      out.println("    <h1>Photo</h1>");
      out.println("    <img src=images.jsp?ctype=me>");
      out.println("    <em>Photo</em>");
      out.println("  </body>");
      out.println("</html>");
    }
%>

-----Original Message-----
From: Alan Williamson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 03, 2002 1:57 PM
To: JDJList
Subject: [jdjlist] RE: Encode a JPEG in JSP/Servlet


||| Servlet.  It's on the subject.

your right ... then i apologise for not reading that properly ... and i
guess you've already checked out google ?  because i know for a fact there
is a plethora of resources on this ... any servlet book (including mine).

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to