struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: How do deal with JPEG in JSP's
Date Tue, 28 Aug 2001 18:52:06 GMT
Thank you all. The problem is solved.

>From: Daniel Steinberg <>
>To: "''" <>
>Subject: RE: How do deal with JPEG in JSP's
>Date: Tue, 28 Aug 2001 10:53:08 -0400
>JSP's are designed to display textual data only.  The out object is a
>PrintWriter, which deals only with character data.  For binary data, such 
>images, you need to use a ServletOutputStream instead.  A recent JDC
>Newsletter presented an example in which getOutputStream() was called from
>within a JSP scriptlet.  This works with some web servers, but it is
>illegal.  The Servlet API explicitly states that if getWriter() and
>getOutputStream() are called on the same response, an IllegalStateException
>is thrown (and the servlet code generated from the JSP calls getWriter()).
>Therefore, the correct solution is to write a servlet instead of a JSP.  (I
>presume that the Struts ActionForward mechanism supports forwarding to a
>-----Original Message-----
>Sent: Tuesday, August 28, 2001 9:31 AM
>Subject: How do deal with JPEG in JSP's
>I am storing jpeg images in oracle as BLOB. I am using the
>connection.getBlob() method to retrieve the images. When I write this back
>as a jpeg file it works great. How do I display the image in JSP's? Here is
>the code I am using.
><%@ page import="java.sql.* ,java.util.*" %>
><%@ page errorPage="error.jsp"%>
><%@ page buffer="50kb"%>
><jsp:useBean id="connection" class="ITTPDB" />
>String sql="select *  from IMAGETEST";
>ResultSet result=connection.executeQuery(sql);
>char c;
>byte [] b;
>int i=0;
>if ( {
>Blob blob=result.getBlob("PHOTO");
>b = blob.getBytes(1,(int)blob.length()+1);
>//writing to file works
> fos = new 
>// Displaying in JSP does Not
>while (i<blob.length()) {
>   i++;
>   }
>Get your FREE download of MSN Explorer at

Get your FREE download of MSN Explorer at

View raw message