• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange behaviour in HttpURLConnection to Servlet communication

 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to upload pictures on a server using HttpURLConnection.

My servlet is deployed in Tomcat 5.5.17.

The problem is that the upload never stops and the wrong data is uploaded.

On the server the uploaded value is allways 255 for each byte.

I belive that the communication is binary.

Did anyone encounterd this problem?
Any help will be appreciated.

Thank you.


Servlet code:




Client code:



web.xml descriptor:

 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It apears that the first byte that was read from the file is sent over and over to the server.

Couldn't found out more.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int msg = is.read();
while(msg != -1)
{
fos.write(msg);
}


You're only ever reading the first byte. What you want is probably something like (haven't tested it):

int msg;
while((msg = is.read()) != -1)
{
fos.write(msg);
}
 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was it.

Sometimes is right infront of you and you just can't see it.

Thank you Ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic