0

We have a form which once submitted a file is created and returned. I created a java method which does the post and a ok status is returned. However how am i able to download the file after the post?

Sorry for not being clear its driving me crazy. We have a business object which generates reports based on parameters sent to it. Once the form is filled in the browser a pop up comes up (save/open) file. What i want to do is create a java standalone program that will sit on my desktop so that when I run this programing (passing it my name and password and URL to post to, this is done already) it will download the file that is created on the server side. The problem is that I don't know where the file is stored (if it is stored) on the server or the name of the file. All i know is that on the browser we go to the form fill it in and the file is returned to the browser. So far the post is working.

Mohamed
  • 567
  • 1
  • 9
  • 21
  • Saned , May be [this][1] similar thread will answer your question. [1]: http://stackoverflow.com/questions/5085105/sending-files-from-server-to-client-in-java – Rohan Grover Jun 13 '12 at 19:13
  • Make a request to the same app to download it? But you already have the file, why would you need to download what you just uploaded? – Dave Newton Jun 13 '12 at 19:14
  • @Dave, as I understand, the file is created on the server side after the post. – Rohan Grover Jun 13 '12 at 19:14
  • Apache httpClient has this functionality – ControlAltDel Jun 13 '12 at 19:15
  • @Rohan Which is why I said make a request to the same web app to download the file. – Dave Newton Jun 13 '12 at 19:16
  • Can you post the code that you already have? – kjp Jun 13 '12 at 19:16
  • 1
    @SanedMohamed, you need to provide more details--please edit your question to describe precisely what you're trying to accomplish: download the file from what? A client app, as what posted it? Streaming the file from within a web app? Or...? – Dave Newton Jun 13 '12 at 19:17
  • @Dave, Of course.But perhaps Saned wants to know how? Lets see if he clarifies. – Rohan Grover Jun 13 '12 at 19:20
  • @ Dave and Rohan. Thank you for the answer its my fault I didn't ask the question clearly. But that is not what we want to do. We don't want to upload the file to the server we want to download the file from the server. – Mohamed Jun 14 '12 at 14:22

1 Answers1

0

When you are on the form in the browser (e.g. http://localhost/my/form) you should inspect the source of the page (IE is Menu View > Source ). In the source you should search for a form tag. This tag contains an action value like:

<form action="myaction.dhtml" method="...>

</form>

So the URL to request is http://localhost/myaction.dhtml and the servers response will be a "file". Good.

You may send the same request that does the browser from Java. To not code all that stuff again you may use a library like HttpComponents.

Probably your form is sending parameters too to the server (user name, password, etc). Look at the form components what parameters the server expect. Your URL may looks like this:

http://localhost/myaction.dhtml?name=Joe;pass=myPassWRD

You don't have to know where the file is stored, but you will need the correct URL that the server will use to take or generate the correct data and send to the client.

PeterMmm
  • 24,152
  • 13
  • 73
  • 111