Reputation: 21012
I am wanting to post data to an html form on a website I have. So far I was testing it with:
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("website URL");
postMethod.addParameter("company_label", customerCompany);
postMethod.addParameter("customer_name_label", customerName);
try {
httpClient.executeMethod(postMethod);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
String resp = postMethod.getResponseBodyAsString();
} else {
//...postMethod.getStatusLine();
}
But it throws this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66)
at main.main(main.java:113)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Am I on the right path to do what I want or should I be doing this differently?
The form I am trying to use looks like
<form name ='XXXXXXX' method='post' onSubmit='return validate_b3cdee6457e94aae9dee29379f9b9470()'>
<input type='hidden' name='done' value='XXXX' border='0'>
<input type='hidden' name='version' value='2' border='0'>
<table border='0' cellspacing='1' cellpadding='2' width='50%' >
<tr>
<td><table border='0' cellspacing='1' cellpadding='2' width='50%' >
<tr>
<td class='DarkText' style='color:red'><div id='XXXXXXXX' style='display:none;'></div></td>
</tr>
</table>
<div id='div_webForm_b3cdee6457e94aae9dee29379f9b9470'>
<table border='0' cellspacing='1' cellpadding='2' width='100%' >
<tr valign='top' id='text_field_row_company' >
<td style='' width='20%' id="company_label" nowrap class='FormLabel' >Company</td>
<td class='FormField' ><input id="company" type='text' name='company' size='30' maxlength='255' class='inputForm' value="" ></td>
</tr>
<tr valign='top' id='text_field_row_customer_name' >
<td style='' width='20%' id="customer_name_label" nowrap class='FormLabel' >Customer Name</td>
<td class='FormField' ><input id="customer_name" type='text' name='customer_name' size='30' maxlength='255' class='inputForm' value="" ></td>
</tr>
<tr valign='top' id='text_field_row_phone' >
<td style='' width='20%' id="phone_label" nowrap class='FormLabel' >Phone</td>
<td class='FormField' ><input id="phone" type='text' name='phone' size='30' maxlength='255' class='inputForm' value="" ></td>
</tr>
<tr valign='top' id='text_field_row_email' >
<td style='' width='20%' id="email_label" nowrap class='FormLabel' >Email</td>
<td class='FormField' ><input id="email" type='text' name='email' size='30' maxlength='255' class='inputForm' value="" ></td>
</tr>
<tr valign='top' id='text_field_row_needs' >
<td style='' width='20%' id="needs_label" nowrap class='FormLabel' >Needs</td>
<td class='FormField' ><input id="needs" type='text' name='needs' size='30' maxlength='255' class='inputForm' value="" ></td>
</tr>
<tr valign='top' id='field_row_id_other_needs' >
<td style='' width='20%' height=28px nowrap class='FormLabel' id='field_cell_label_id_other_needs' >Other Needs</td>
<td class='FormField' id='field_cell_value_id_other_needs' ><textarea id='other_needs' name='other_needs' rows='5' cols='30' class='inputForm' ></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submitButtonName' value='Submit' border='0' ></td>
</tr>
</table>
</div></td>
</tr>
</table>
</form>
Upvotes: 0
Views: 393
Reputation: 7625
Your code works ok with me with 3 jars and Open JDK 1.6
commons-httpclient-3.1.jar
commons-logging/1.0.4/commons-logging-1.0.4.jar
commons-codec/1.2/commons-codec-1.2.jar
I've tested on:
PostMethod method = new PostMethod("http://search.yahoo.com/search");
Good luck!
Upvotes: 1
Reputation: 34367
Its complaining about the Appache Commons Library. Please download commons-logging.xxxxxx.jar
from Apache commons download and add in your project lib/classpath.
Upvotes: 1
Reputation: 22171
You may miss the concerned jar file within your lib folder:
Download it here: http://commons.apache.org/logging/download_logging.cgi
Upvotes: 1
Reputation: 576
Yes. The HTTPClient code is trying to use code from somewhere else... from the Apache logging stuff. You need to include that JAR into your classpath (in Eclipse its in the Project Properties->Java Build Path:Libraris tab.
See: Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception
and others.
Upvotes: 1