Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Send a Http request using Swing GUI

 
Sandeep R Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using swing GUI....when i click submit, a new thread should be created and the data in the form should be sent to a servlet as http request...and the servlet should update the database accordingly and send back a proper response back ....
someone please help me out...
thanks in advance

--------------------

Thanks,
San
[ April 24, 2007: Message edited by: Sandeep Kumar R ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sandeep-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, you can use the java.net.HttpUrlConnection class for this, or -for more convenience and flexibility- the Jakarta Commons HttpClient library.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the Apache Commons HttpClient...
 
Sandeep R Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer ...
 
rohit leeta
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, HttpClient is very powerful. It comes with some examples too.
 
jad yuuu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can do it the simple way:

try {

URL url = new URL("http://www.yourURL.com/login.php");
HttpURLConnection con =(HttpURLConnection) url.openConnection();


con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

DataOutputStream printout = new DataOutputStream(con.getOutputStream());

// This is the POST
String content ="email=jad939933@hotmail.com&pass=577383";


printout.writeBytes(content);
printout.flush();
printout.close();





DataInputStream input = new DataInputStream(con.getInputStream());
String str;
//Read the response
while (null != ((str = input.readLine()))) {
System.out.println(str);
}
input.close();


} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

This is described in more details on http://www.gulany.com/?page_id=7
[ May 07, 2007: Message edited by: jad yuuu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic