Handling redirections in Java

Hi,

I'm developing a HTTP download manager using Java. Now I see that some of the URLs don't end with a real file name. But, once they start downloading, they download a differently named file. How do I handle such situations?

What are the different ways in which redirection can occur? How can I handle each of them?

Also, could u plz post a sample code for determining the real file name using the "Content-Disposition" header field. I find that the format of the header field value varies between different sites.

[543 byte] By [chasana] at [2007-11-26 22:47:05]
# 1

The filename is probably being sent in the form of HTTP headers (the filename attribute in the Content-Disposition header, as you mention), so this probably isn't redirection at work, just dynamic HTTP content. Basically the server resolves the URL to a file or similar resource (may be a blob in a database, but it doesn't matter), sends the appropriate headers which includes the filename, content type and length. then the file data. This is not really all that different to how a file is normally sent, only the URL itself does not include the filename but nevertheless allows the http server to locate it in whatever format it is stored.

The format of the headers is part of the HTTP specification.

deepravea at 2007-7-10 12:05:47 > top of Java-index,Java Essentials,New To Java...