如何将文件从小程序发送到 gwt 服务器?
我正在尝试将文件从小程序发送到我的服务器 GWT。在另一个应用程序 JSF 中,我将打开与我的 servlet 的 HTTP 连接。
如何创建 GWT 服务器?我尝试将 servlet 插入 web.xml 但它似乎被忽略。
我需要使用远程服务吗?我该怎么办?
下面的代码将applet 和servlet 映射在web.xml 中。
URL urlDoServlet = new URL("http://192.168.3.100:8080/gwtapp/conection?action=send");
HttpURLConnection conexaoComServlet = (HttpURLConnection) urlDoServlet.openConnection();
conexaoComServlet.setDoOutput(true);
conexaoComServlet.setDoInput(true);
conexaoComServlet.setUseCaches(false);
conexaoComServlet.setDefaultUseCaches(false);
File doc = new File(file);
conexaoComServlet.setRequestMethod("POST");
conexaoComServlet.setRequestProperty("Content-Type", "application/octet-stream");
FileInputStream fis = new FileInputStream(doc);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream bos = new BufferedOutputStream(conexaoComServlet.getOutputStream());
int read;
byte[] buffer = new byte[8192];
while((read = bis.read(buffer)) != -1)
{
bos.write(buffer, 0, read);
}
bis.close();
fis.close();
bos.flush();
bos.close();
// get the answer.
ObjectInputStream ois = new ObjectInputStream(conexaoComServlet.getInputStream());
boolean bool = (Boolean) ois.readObject();
ois.close();
conexaoComServlet.getResponseMessage();
conexaoComServlet.disconnect();
<servlet>
<servlet-name>ConectionServlet</servlet-name>
<servlet-class>br.com.gwtapp.server.servlets.ConectionFileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>conectionServlet</servlet-name>
<url-pattern>/gwtapp/conection</url-pattern>
</servlet-mapping>
I'm trying to send a file from an applet to my server GWT. In another application, JSF, I would open an HTTP connection with my servlet.
How do I make whit an GWT server? I tried to insert my servlet in web.xml but it seems to be ignored.
I need to use a RemoteService? How can I do?
The following code of the applet and servlet mapping in web.xml.
URL urlDoServlet = new URL("http://192.168.3.100:8080/gwtapp/conection?action=send");
HttpURLConnection conexaoComServlet = (HttpURLConnection) urlDoServlet.openConnection();
conexaoComServlet.setDoOutput(true);
conexaoComServlet.setDoInput(true);
conexaoComServlet.setUseCaches(false);
conexaoComServlet.setDefaultUseCaches(false);
File doc = new File(file);
conexaoComServlet.setRequestMethod("POST");
conexaoComServlet.setRequestProperty("Content-Type", "application/octet-stream");
FileInputStream fis = new FileInputStream(doc);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream bos = new BufferedOutputStream(conexaoComServlet.getOutputStream());
int read;
byte[] buffer = new byte[8192];
while((read = bis.read(buffer)) != -1)
{
bos.write(buffer, 0, read);
}
bis.close();
fis.close();
bos.flush();
bos.close();
// get the answer.
ObjectInputStream ois = new ObjectInputStream(conexaoComServlet.getInputStream());
boolean bool = (Boolean) ois.readObject();
ois.close();
conexaoComServlet.getResponseMessage();
conexaoComServlet.disconnect();
<servlet>
<servlet-name>ConectionServlet</servlet-name>
<servlet-class>br.com.gwtapp.server.servlets.ConectionFileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>conectionServlet</servlet-name>
<url-pattern>/gwtapp/conection</url-pattern>
</servlet-mapping>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
/gwtapp/conection
替换为/conection
并告诉我们如果有效的话:)try replace
<url-pattern>/gwtapp/conection</url-pattern>
by<url-pattern>/conection</url-pattern>
and tell us if that works :)我找到了一个新的实现,使用 caarlos0 和 raduq-santos:
在我的小程序上...
I've found a new implementation for that with caarlos0 and raduq-santos:
and on my applet...