Envío de datos de swing a Servlet

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)?

I am passing data to Servlet using this code:

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

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?

preguntado el 01 de febrero de 12 a las 04:02

2 Respuestas

Tienes que usar HttpUrlConnection in order to communicate using HttpRequest

Consulte nuestra página

contestado el 23 de mayo de 17 a las 15:05

url = new URL(targetURL); connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");I have seen this code in some link,targeturl=target o the servlet-is it correct?? Do we need to set all the connection parameters like setreqmethod,set req property??? - user1168647

It works just the same as Java Applets, you can find more information here: http://www.coderanch.com/how-to/java/AppletsFaq#servlet

I'd highly reccommend BalusC's introduction to Servlet's and DAO's aquí también.

Respondido 01 Feb 12, 08:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.