File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Image is not displayed from Oracle table using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Image is not displayed from Oracle table using servlet" Watch "Image is not displayed from Oracle table using servlet" New topic
Author

Image is not displayed from Oracle table using servlet

subir adhikari
Greenhorn

Joined: Jul 17, 2012
Posts: 4
After a long trial ,I finally successfully able to upload an image to an oracle database. At least my code says so. However to check whether the image has been successfully I wrote a servlet. After running the servlet I get a black screen in my browser and nothing else. The servlet code is:



By the way, as I am totally new to this, I took extensive help from this link.http://www.srikanthtechnologies.com/blog/java/fileupload.aspx.
EDIT : I get the black screen if only viewed from FF , but if viewed from internal web browser of Eclipse it shows me a single word upload . Very strange behavior!! Please help!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

InputStream.read(byte[]) is not guaranteed to read everything in one call. No matter what InputStream you use, you should always use a loop until you're actually done. You can find an example in https://www.coderanch.com/how-to/java/AvailableDoesntDoWhatYouThinkItDoes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
subir adhikari
Greenhorn

Joined: Jul 17, 2012
Posts: 4
So I changed the code a little bit and wrote:
But it did not change the result.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You're still not doing it right. You are now reading data twice in each loop iteration. The data read by the first one will be discarded and overwritten by the data read by the second one. Also, you write all contents of the byte[], even if less was read. Didn't you check the link I posted? It shows you exactly how you can do this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image is not displayed from Oracle table using servlet
 
Similar Threads
GET Method Working But POST is not
Servlet -> XML
Problem Uploading Image to DB
upload image using ServletInputStream
how to call JSP from Servlet