简体   繁体   English

Java发布和下载文件

[英]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. 我创建了一个Java方法来执行发布,并返回确定状态。 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. 我想做的是创建一个Java独立程序,该程序将位于我的桌面上,以便在我运行该程序时(将其名称,密码和URL传递给它,此操作已经完成)将下载创建的文件在服务器端。 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 ). 当您使用浏览器中的表单(例如http://localhost/my/form )时,应检查页面的源(IE是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". 因此,要请求的URL是http://localhost/myaction.dhtml ,服务器响应将是“文件”。 Good. 好。

You may send the same request that does the browser from Java. 您可以从Java发送与浏览器相同的请求。 To not code all that stuff again you may use a library like HttpComponents . 为了不再编写所有这些东西,可以使用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. 您不必知道文件的存储位置,但是您将需要服务器用来获取或生成正确数据并将其发送到客户端的正确URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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