Reputation: 768
I am trying to get the value of a checkbox from a posted form data. I already have the form working because I can get the value of a file easily enough(I have omitted the file form field in the code below), but the checkbox wont return anything other than null. What am I doing wrong?
Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = request.getParameter("isTransform");
System.out.println("parameter: " + str);
}
Html Client:
<form enctype="multipart/form-data" id="compareForm1" >
<input type="checkbox" value="true" name="isTransform" id="isTransform1" >
</form>
I have jquery.form.js sending the actual post
var options = {
url: "http://localhost:8080/TestingTomcat/someClassName",
type: "POST",
success: function (html){
$("#placeholder").html(html);
change_active("comparison_page");
}
};
$("#compareForm1").submit(function () {
$(this).ajaxSubmit(options);
return false;
});
Actual Post data:
POSTDATA =-----------------------------153501500631101
Content-Disposition: form-data; name="isTransform"
true
-----------------------------153501500631101
Content-Disposition: form-data; name="isTransform"
true
-----------------------------153501500631101--
And the result I get with the button clicked or unclicked is:
parameter: null
Upvotes: 1
Views: 2694
Reputation: 7957
Parameters post from 'multipart/form-data' form can not be get from getParameter method. You should use 3rd-party library to handle the multipart data for parse the content of req.getInputStream() by yourself. I think Apache Commons fileUpload will help you.
Upvotes: 3