• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Send a Http request using Swing GUI

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use the Apache Commons HttpClient...
 
Sandeep R Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer ...
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, HttpClient is very powerful. It comes with some examples too.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic