File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URLConnection" Watch "URLConnection" New topic


Jonathan Cone

Joined: May 22, 2005
Posts: 24
Hi gang,

I'm working on a web application in which I would like a servlet to connect to a 3rd party website and download a file into my webapp context. What I need help with is a game plan because there are some things I am unsure about:

1) I see that I should use a URLConnection object to do the brunt of the work.
2) Am I going to need two URLConnection objects since I need to log in first - or rather does one persist across two requests (does this even qualify as two requests)?
3) What's the best way to validate if the login was successful so I know if I can move on to the file download?

Any advice is always appreciated.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I think you will find the HTTPclient toolkit to be very helpful. It will maintain any cookies needed over multiple requests, and help with response handling. No need to reinvent the wheel!

Jonathan Cone

Joined: May 22, 2005
Posts: 24

As I'm looking over HttpClient, I can see that its exactly what I was looking for - thanks!

I agree. Here's the link:
subject: URLConnection
It's not a secret anymore!