将数据从swing发送到Servlet [英] Sending data from swing to Servlet

查看:171
本文介绍了将数据从swing发送到Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to send data (form data) from a Swing to the servlet. Is it as simple as specifying in action attribute as in html(form)?

我使用以下代码将数据传递给Servlet:

I am passing data to Servlet using this code:

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

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

What is that I have to pass to url i.e in place of targetURL (do I need to mention Servlet location) so that I can retrieve values in the servlet?

推荐答案

您需要使用 HttpUrlConnection 使用 HttpRequest进行沟通

参见

  • how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests

这篇关于将数据从swing发送到Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆