This question already has an answer here:
I'm trying to get the value of a checkbox from a field (whether it is checked or not). The form method is post and the encoding is multipart because I'm uploading a file with the same form action.
I succeeded on getting the values of other fields (simple TextBox and even the file from the FileUpload Widget). However, when it comes to the values of a CheckBox widget, I'm always getting the value "on" ... At first I thought it was "on" when it was checked and "off" when it was unchecked. However, I'm always getting "on" no matter what.
The form is a very simple one so no need to show it to you, instead, here is the code I'm using to get fields values from the servlet:
FileItemIterator ierator = uplaod.getItemIterator(request);
while(iterator.hasNext()) {
FileItemStream item = iterator.next();
if (item.isFormField()) {
String fieldValue = Streams.asString(item.openStream());
}
}
Aucun commentaire:
Enregistrer un commentaire