简体   繁体   中英

java post and download file

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.

When you are on the form in the browser (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM