如何使用 fileUploader 和 GWT 2.4 从服务器检索 inputStream?

发布于 2024-12-19 04:57:43 字数 831 浏览 6 评论 0原文

我有一个 fileUploader 小部件,用于选择 xml 文件。然后,当用户提交所选文件时,我有一个按钮调用 viewImpl 类中的处理程序。如果我理解正确,我会从 formPanel 进行提交,并且文件位于服务器上。

@UiHandler("calculateComplexityButton")
    void onClickCalculateComplexity(ClickEvent e){
        formPanel.submit();
        //How do I get the inputStream back to here????
        presenter.getTask(inputStream);
    }

我的问题是如何从服务器获取 inputStream?我尝试使用 RPC 调用来完成所有这些操作,但是当我尝试获取 inputStream 时,我没有从服务器上获取任何内容。我尝试过:

inputStream = request.getInputStream();

但它似乎是空的。对此有什么想法吗?

我删除了 RPC 代码并使用了此处找到的简单 HTTPRequest。这让我进入 servlet,但请求没有文件流。当我到达代码中的这一行时:

FileItemIterator iter = upload.getItemIterator(request); //Nothing is here in iter.

I have a fileUploader widget that I'm using to select an xml file. I then have a button that calls my handler in the viewImpl class when the user submits the selected file. If I understand things correctly, from there I do a submit from the formPanel and the file is on the server.

@UiHandler("calculateComplexityButton")
    void onClickCalculateComplexity(ClickEvent e){
        formPanel.submit();
        //How do I get the inputStream back to here????
        presenter.getTask(inputStream);
    }

My problem is how do I get the inputStream off the server? I tried using an RPC call for all this, but when I try to get the inputStream I'm not pulling anything off the server. I tried:

inputStream = request.getInputStream();

but it appears to be empty. Any ideas on this?

I dropped the RPC code and used a simple HTTPRequest I found here. That gets me to the servlet, but the request doesn't have the file stream. When I reach this line in the code:

FileItemIterator iter = upload.getItemIterator(request); //Nothing is here in iter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-12-26 04:57:43

您无法通过 RPC 上传,这就是为什么您必须将表单提交到 servlet。

final FormPanel form = new FormPanel();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
form.setAction("/upload");

因此,当您执行 form.submit() 时,它会将您的文件发送到 Action(Servlet)。在服务器端,您可以使用 apache 的 lib 形式(commons-fileupload)。你有很多不同的方式来获取你的文件,你可以保存在磁盘上,在内存上读取......

You can not make an upload via RPC, thats why you have to submit your form to a servlet.

final FormPanel form = new FormPanel();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
form.setAction("/upload");

So, when you do form.submit() it will send your file to the Action(Servlet). In the server side you can use the lib form apache (commons-fileupload). You have many different way to get your file, you can save on disk, read on memory....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文