Re: Making a Database Image Show Up on a Jsp Page
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]
Re: Making a Database Image Show Up on a Jsp Page
Caldarale, Charles R wrote: From: Philip Cote [mailto:[EMAIL PROTECTED] Subject: Re: Making a Database Image Show Up on a Jsp Page My only sticking point is how I'm supposed to write that binary data to the jpeg file. I think the point people are trying to make is that you don't need to write any file at all. The bytes of the image should be output as part of the response stream, using the appropriate MIME type. Or maybe I don't really understand the problem. - Chuck No, it was me who didn't understand the answer. I never thought of servlets being used like that. I've always thought of them as tools that collected data from the appropriate sources and then rendered text and html and that's it. The whole idea of streaming binary data based on a different MIME type than that never occurred to me before. When I finally got it, the solution came together perfectly. It was pretty cool. THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - 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]
Making a Database Image Show Up on a Jsp Page
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? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Making a Database Image Show Up on a Jsp Page
You could do it easily with a servlet - read the blob as a byte[], and server it up in response to a request to /myservlet/imageid/image.jpg, where /imageid/ is used to provide the id of the record that contains the image. Larry On 8/24/05, Philip Cote [EMAIL PROTECTED] 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? - 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]
Re: Making a Database Image Show Up on a Jsp Page
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]
Re: Making a Database Image Show Up on a Jsp Page
--- 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]
Re: Making a Database Image Show Up on a Jsp Page
Edmund Urbani 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'm using Windows XP. I checked the tomcat configuration box. I'm starting Tomcat with the default settings with Tomcat security off. I believe my JVM is also set to default mode though I'm not really sure how to verify this. 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 ...). I'm really not sure you mean by send them back directly drom memory. Does this have to do with setting the res.setContentType() to image/jpeg rather than text/html. Because if that's the case, then I'm definitely in alien territory. I did try that and it caused firefox to want to download a 0 byte long file. The bright side is Larry is right. Writing the servlet was a breeze as was getting the binary data out of the database. It was easy to have my servlet forward over to the jsp page where the image would actually be displayed. I'm even getting my bean on that page to pull database records. My only sticking point is how I'm supposed to write that binary data to the jpeg file . Is this more an issue of my understanding of the java.io libraries? I thought I understood them but maybe I'm missing the boat on this one. Edmund - 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]
RE: Making a Database Image Show Up on a Jsp Page
From: Philip Cote [mailto:[EMAIL PROTECTED] Subject: Re: Making a Database Image Show Up on a Jsp Page My only sticking point is how I'm supposed to write that binary data to the jpeg file. I think the point people are trying to make is that you don't need to write any file at all. The bytes of the image should be output as part of the response stream, using the appropriate MIME type. Or maybe I don't really understand the problem. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]