本文介绍了将数据从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
- how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
更多推荐
将数据从swing发送到Servlet
发布评论