Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在客户端发送的GoogleAWTServlet中读取数据_Java_Networking_Servlets - Fatal编程技术网

Java 在客户端发送的GoogleAWTServlet中读取数据

Java 在客户端发送的GoogleAWTServlet中读取数据,java,networking,servlets,Java,Networking,Servlets,我想从桌面应用程序向google awt servelet发送一些数据 我目前正在我的系统(localhost)中尝试这一点,因为我已经安装了eclipse插件 我正在发送这样的数据 URL url = new URL("http://localhost:8888/calendar"); URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true); PrintWriter out = ne

我想从桌面应用程序向google awt servelet发送一些数据
我目前正在我的系统(localhost)中尝试这一点,因为我已经安装了eclipse插件
我正在发送这样的数据

URL url = new URL("http://localhost:8888/calendar");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
PrintWriter out = new PrintWriter(urlConnection.getOutputStream());

String stringTosend = URLEncoder.encode(tf.getText(), "UTF-8");
out.write(stringTosend);
我的SERVLET是这样的

public class CalendarServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        String input = req.getReader().readLine();
        resp.getWriter().println(input);
    }
}
但我得到的是空的

URLConnection connection = new URL("http://localhost:8888/calendar").openConnection();
connection.setDoOutput(true); // Triggers POST.
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
OutputStream output = null;
try {
     output = connection.getOutputStream();
     output.write(stringTosend.getBytes(charset));
} finally {
     if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
}
InputStream response = connection.getInputStream();
参考