私が持っているウェブサイトのhtmlフォームにデータを投稿したいと思っています。これまでのところ、次の方法でテストしていました。
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();
}
しかし、それはこのエラーをスローします
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)
私は自分がやりたいことをするのに正しい道を進んでいますか、それともこれを別の方法で行うべきですか?
私が使用しようとしているフォームは次のようになります
<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>