1

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 
5
  • When it is ajax call don't you need to append the param& value to URL? Ajax calls are not full form submits. Commented Jul 10, 2012 at 20:45
  • I am relatively new to ajax... I had assumed since the file sent fine I should be able to do something simple like a check box in the same way Commented Jul 10, 2012 at 20:46
  • For simple test try this, localhost:8080/TestingTomcat/someClassName?isTransform=false in url section Commented Jul 10, 2012 at 20:48
  • Hey hey! It worked great but this leads me to another question. If I want to submit an entire form do I have to append it to the url? Shouldn't there be some way to encode it into a POST request? Commented Jul 10, 2012 at 20:51
  • Ajax submits partial form data (which you want to update). If you want full form, don't do ajax. Commented Jul 10, 2012 at 20:58

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.