简体   繁体   English

与Tomcat的HttpURLConnection

[英]HttpURLConnection to Tomcat

I am trying to connect from a java desktop application to a jsp Servlet to send a file. 我正在尝试从Java桌面应用程序连接到jsp Servlet以发送文件。

Clientcoding: 客户端编码:

HttpURLConnection urlConnection = null;
URL url = null;
url = new URL("http://127.0.0.1:8080/emobile/AddTripMobile");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
OutputStream out = new BufferedOutputStream(
urlConnection.getOutputStream());

out.write(12); //The data to send
out.flush();

If I connect with the desktop application to the server nothing happens. 如果我将桌面应用程序连接到服务器,则不会发生任何事情。 (I set a breakpoint in the doGet and doPost) (我在doGet和doPost中设置了一个断点)

Any suggestions? 有什么建议么?

尝试关闭输出流。

You need to add the following : 您需要添加以下内容:

InputStream is = urlConnection.getInputStream();
out.write(12); //The data to send
out.flush();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM