繁体   English   中英

与Tomcat的HttpURLConnection

[英]HttpURLConnection to Tomcat

我正在尝试从Java桌面应用程序连接到jsp Servlet以发送文件。

客户端编码:

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();

如果我将桌面应用程序连接到服务器,则不会发生任何事情。 (我在doGet和doPost中设置了一个断点)

有什么建议么?

尝试关闭输出流。

您需要添加以下内容:

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