【问题标题】:Sending data from swing to Servlet将数据从 swing 发送到 Servlet
【发布时间】:2012-02-01 04:00:16
【问题描述】:

如何将数据(表单数据)从 Swing 发送到 servlet。是否像在 html(form) 中指定 action 属性一样简单?

我正在使用此代码将数据传递给 Servlet:

URL url = new URL(targetURL); 
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");

我必须将什么传递给 url,即代替 targetURL(我是否需要提及 Servlet 位置)以便我可以检索 servlet 中的值?

【问题讨论】:

    标签: java swing servlets


    【解决方案1】:

    您需要使用HttpUrlConnection 才能使用HttpRequest 进行通信

    【讨论】:

    • url = 新 URL(targetURL);连接 = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");我在一些链接中看到过这段代码,targeturl=target o servlet-是否正确?我们需要设置所有的连接参数,比如setreqmethod,set req property???
    【解决方案2】:

    它的工作原理与 Java 小程序相同,您可以在此处找到更多信息:http://www.coderanch.com/how-to/java/AppletsFaq#servlet

    我也强烈推荐 BalusC 对 Servlet 和 DAO 的 here 的介绍。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-27
      • 2014-07-21
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      相关资源
      最近更新 更多