Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to Send a Http request using Swing GUI

 
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 ]
 
Rancher
Posts: 43016
76
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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 ...
 
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.
 
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 ]
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic