aspose file tools*
The moose likes Servlets and the fly likes Strange behaviour in HttpURLConnection to Servlet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Strange behaviour in HttpURLConnection to Servlet communication" Watch "Strange behaviour in HttpURLConnection to Servlet communication" New topic
Author

Strange behaviour in HttpURLConnection to Servlet communication

Ioan Berciu
Greenhorn

Joined: Nov 17, 2002
Posts: 15
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:



JOE
Ioan Berciu
Greenhorn

Joined: Nov 17, 2002
Posts: 15
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
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
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);
}


Ping & DNS - my free Android networking tools app
Ioan Berciu
Greenhorn

Joined: Nov 17, 2002
Posts: 15
That was it.

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

Thank you Ulf.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange behaviour in HttpURLConnection to Servlet communication