是否可以通过 GWT RPC Servlet 上传文件?
是否可以使用 Google 的 GWT RPC 机制创建文件上传? 现在我正在使用一个简单的 HTTPServlet 和 doPost 方法,该方法从表单中获取地址!
是否可以(无需 gwtupload 等库的帮助)通过 GWT FileUpload Widget 将 XML 文件上传到 RPC 服务并使用文件内容?
BR; 迈贝克斯
is it possible to create a file upload with Googles GWT RPC mechanism?
As now I'm using a simple HTTPServlet with a doPost Method which gets addressed from the form!
Is it (without the help of libs like gwtupload) possible to upload a XML file via GWTs FileUpload Widget to a RPC Service and work with the content of the file?
BR;
mybecks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,正如您提到的,有两种使用 gwtupload 上传文件的方法和通过 gwt-rpc 上传文件的方法,由于浏览器安全性,这种方法有点困难。要使用 gwt-rpc 实现,您应该在继承
RemoteServiceServlet
的服务实现中重写service(final HttpServletRequest request,HttpServletResponse response)
方法。对于客户端,您应该有类似这样的代码:
在
service
方法中,您可以使用 使用 FileUpload,不要忘记在 web.xml 中注册 fileupload url 模式,并在继承的服务接口中注册@RemoteServiceRelativePath("path")
远程服务
。祝你好运!Actually, there are two ways of uploading file with gwtupload as you mentioned and via gwt-rpc this one is a bit difficult due to browser security. For implementing with gwt-rpc you should override
service(final HttpServletRequest request,HttpServletResponse response)
method inside your service implementation which inheritsRemoteServiceServlet
.For client-side you should have code something like this:
Inside
service
method you can get the file with using FileUpload, and don't forget registering fileupload url pattern in your web.xml and also@RemoteServiceRelativePath("path")
in your service interface which inheritsRemoteService
. Good Luck!这是可能的,但并不那么容易。首先,您需要能够从客户端代码读取文件。大多数浏览器都支持 FileReader API,但并非全部。因此,对于 Internet Explorer,您将必须使用 Flash 或其他一些插件技术来访问文件。
另外,默认情况下,GWT 中没有文件读取器 API 的绑定,因此您必须自己执行此操作。
接下来,您将通过 GWT -RPC 将文件作为 Base64 编码字符串发送,并且必须在服务器端进行解码。因此,如果您的用户开始上传大量大文件(大约 20 MB),您可能会遇到一些内存问题。
It is possible, but it is not so easy. First you will need to be able to read file from client code. Most of the browsers support FileReader API, but not all of them. So fo Internet Explorer you will have to use flash or some other plugin technology for accessing files.
Also by default there is no binding for File Reader API in GWT, so you will have to do it by yourself.
Next thing is that you are going to send files as Base64 encoded string over GWT -RPC and you'll have to decode on server-side. Because of this you might run into some memory problems if your users start uploading a lot of large files (around 20 mb).