• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image is not displayed from Oracle table using servlet

 
subir adhikari
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
subir adhikari
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I changed the code a little bit and wrote:
But it did not change the result.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic