如何使用 fileUploader 和 GWT 2.4 从服务器检索 inputStream?
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过 RPC 上传,这就是为什么您必须将表单提交到 servlet。
因此,当您执行 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.
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....