Hi

we develop a servlet in order to send directly the image to the browser,
here is the code :

     public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
     {

          ServletOutputStream html_out;
          java.lang.String query = SELECT IMAGE FROM DATABASE WHERE
IMAGENUMBER = " //replace with your select

          Connection OraConn =  conn.getConnection();
          Statement stmt = OraConn.createStatement();
          // select image from database
          ResultSet Result = stmt.executeQuery(query+" "+files);
          if (Result.next())
          {
               res.setContentType("image/jpeg");
               byte[] bytes = Result.getBytes(1);
               html_out = res.getOutputStream();
               html_out.write(bytes);
          }
     }

     if you want to use less memory, send in 4k blocks

     Statement stmt = conn.createStatement();
      // select image from database
     ResultSet Result = stmt.executeQuery(query+" "+files);
     ServletOutputStream out = res.getOutputStream();
     while (Result.next())
     {
         res.setContentType("image/jpeg");
         BufferedInputStream gifData = new 
BufferedInputStream(Result.getBinaryStream(1));
          byte[] buf = new byte[4 * 1024];  // 4K buffer
          int len;
          while ((len = gifData.read(buf, 0, buf.length)) != -1)
            out.write(buf, 0, len);
      }

bye

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to