GeeCON Prague 2014*
The moose likes Servlets and the fly likes Problem with HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with HttpURLConnection" Watch "Problem with HttpURLConnection" New topic
Author

Problem with HttpURLConnection

Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
I have got strange problem,

I have got one servlet, which creates a file on my hard drive. It's working just fine, when I write http://localhost:8080/WI/Tester in webbrowser its creating this file.

I have got another servlet, which is making HttpURLConnection to the first servlet. But the first servlet doesnt create this file then, could somebody tell my why?

here is code:


I don't het any exception or anything...

Thanks...


SCJP, SCWCD, OCUP
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Tomasz Stachlewski wrote:I have got strange problem,

I have got one servlet, which creates a file on my hard drive. It's working just fine, when I write http://localhost:8080/WI/Tester in webbrowser its creating this file.

I have got another servlet, which is making HttpURLConnection to the first servlet. But the first servlet doesnt create this file then, could somebody tell my why?

here is code:


I don't het any exception or anything...

Thanks...


It is probably calling doGet of the servlet and you have written your code in doPost. You can check that by writing log statements


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
No, problem is not here, I had doGet in firstServlet, but it didnt work, so I even replace it and Override service method. Here is the code:


But it is still not working. I was even trying to connect to this from normal Java Application, but still nothing...





I really don't know why... It should be so simple...
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Open the input stream and read the response. That will establish the connection
Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
Heh, It's working, it turned out, that I should use connection.connect() but connection.getResponseCode() ... Strange :P But it's working, thanks anyway.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with HttpURLConnection