I have a simple JSP that contains checkbox and submit button:
<form action="MappingSubmit.jsp" enctype="multipart/form-data" method="POST" name="fileSubmit">
<input type="checkbox" name="scan" value="scan">Scan immediately<br><br>
<input type="submit" value="Submit">
</form>
and a second JSP that should read the submitted data:
<body>
<%
response.getWriter().println(request.getParameter("scan"));
%>
</body>
The problem is that getParameter always returns null.
If I remove the enctype from the form, it works.
Why? No way to use checkbox in a multipart/form-data form?
Thanks
Udi
The default HTML form encoding is
application/x-www-form-urlencoded. ThegetParameter()method is relying on this. Other form encodings are not supported bygetParameter(). When you’re using Servlet 3.0, you should be usinggetParts()for this instead. Or when you’re using Servlet 2.5 or older and/or when you’re using amultipart/form-dataparser already such as Apache Commons FileUpload, then you should be using this instead to extract the parts.If you’re not using a file upload element
<input type="file">in the same form, then you don’t need theenctype="multipart/form-data"at all. You could just remove it so that it defaults toapplication/x-www-form-urlencodedand you can usegetParameter()the usual way.See also: