| 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: 19216
|
|
|
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
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: 19216
|
|
|
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.
|
 |
 |
|
|
subject: Image is not displayed from Oracle table using servlet
|
|
|