Java:上传文件并取回文件的字符串(内容) [英] Java: Upload file and get back string (contents) of file

查看:124
本文介绍了Java:上传文件并取回文件的字符串(内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有GWT客户端与标准的服务器端Servlets。


  • 我可以从GWT客户端上传文件并阅读它的内容在服务器端

  • 我可以将它作为字符串发送回客户端





我有GWT FormPanel with action(myModule +import)。 FormPanel从servlet调用 POST 。然后浏览器将我重定向到 myurl / import ,以便我可以看到上传文件的内容。



虽然这不是我想要的。我只想回到我的字符串。我在FormPanel中添加了
submitCompleteHandler ,但它没有记录任何结果。



我注意到servlet的方法是 setContentType ,所以我尝试了文本/ html,text / plain ...我不知道应该在那里...



用一句话来说,我想发回String给客户端从没有浏览器的servlet重定向到其他地方。可能吗?

解决方案

由于您提交表单,因此您可以使浏览器更改导航。为了使它以你想要的方式工作,你必须用ajax发送文件。对于GWT,您可以使用 GWTUpload 库。


Hi I have GWT client with standard server-side Servlets.

  • I can upload file from GWT client-side and read it's contents at server-side
  • I can send it back to client as String

BUT

I have GWT FormPanel with action (myModule+"import"). FormPanel invokes POST from servlet. Browser then redirects me to myurl/import so I can see contents of uploaded file.

This is not what I wanted though. I'd simply like to have my String back. I added submitCompleteHandler to my FormPanel, but it doesn't log any results.

I noticed that servlets have method such setContentType so I tried text/html, text/plain ... I don't know what should be there ...

To say it in one sentence, I want to send String back to client from servlet without having browser to redirect me somewhere else. Is it possible?

解决方案

Since you are submitting a form you get your browser to change navigation. In order to make it work the way you want you have to send the file with ajax. For GWT there is the GWTUpload library that allows you to do that.

这篇关于Java:上传文件并取回文件的字符串(内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆