简体   繁体   中英

HttpURLConnection to Tomcat

I am trying to connect from a java desktop application to a jsp Servlet to send a file.

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)

Any suggestions?

尝试关闭输出流。

You need to add the following :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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