Thank you, Wade and everyone else.  ServletOutputStream worked perfectly.

Wade Chandler wrote:

--- Edmund Urbani <[EMAIL PROTECTED]> wrote:

Philip Cote wrote:

I'm trying to write to binary data from a MySQL
database into a jpeg
file so I can show it on a jsp page but I'm not
having much luck. My
bean can create files outside the servlet / jsp
context using the
usual java.io classes.  As I understand it,
java.io classes aren't
allowed for EJBs.  Does this apply to plain java
beans as well? If
so, what are the alternatives for doing what I'm
trying to do?
your java classes can do anything the VM process is
permitted to do, unless you have restricted using a security manager and the catalina.policy file (i think eg. debian tomcat packages do that by default). i'm not sure just jow exactly you are trying to serve those images to the client and why you want to write them (temporarily) to the file system. i would probably want to send them back directly from memory after reading them from the DB as a blob (much like Larry Meadors just suggested while i was writing this ...).

Edmund


---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]



I have never heard that EJB could not use java.io
classes.  That wouldn't make much sense.  Even JDBC
some times needs to use streams for it's data. ByteArrayOutputStream and StringWriter are at times needed to perform a task as well for certain things. Sometimes people will make a servlet like this then
address this servlet for all images.  You'll need to
set the content type of your return and stream the
bytes out of your DB to the response output in your
servlet.  Depending on the type of field you have used
in the DB you can do something like:

java.io.InputStream in = null;
try
{
  in = resultSet.getBinaryStream("columnName");
  java.io.BufferedInputStream bin =
  new java.io.BufferedInputStream(in);
  java.io.BufferedOutputStream bout =
new java.io. BufferedOutputStream(response.getServletOutputStream());
 int iread = bin.read();
 while(iread!=-1)
 {
   bout.write(iread);
   iread = bin.read();
 }
 bout.flush();
}
finally
{
  if(in!=null)
  {
     in.close();
  }
}

Just be sure you have your content type setup and all
you need to do there.  Then you can simply have a
servlet to read images and use as the endpoint in your
IMG tags.  It's not so bad.

Wade

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to