• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange behaviour in HttpURLConnection to Servlet communication

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was it.

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

Thank you Ulf.
 
reply
    Bookmark Topic Watch Topic
  • New Topic