[英]null return value from getParameter (Tomcat Servlet)
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: Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = request.getParameter("isTransform");
System.out.println("parameter: " + str);
}
Html Client: HTML客户端:
<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 我有jquery.form.js发送实际帖子
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
Parameters post from 'multipart/form-data' form can not be get from getParameter method. 从“ multipart / form-data”表单中发布的参数无法从getParameter方法获取。 You should use 3rd-party library to handle the multipart data for parse the content of req.getInputStream() by yourself. 您应该使用3rd-party库来处理多部分数据,以便自己解析req.getInputStream()的内容。 I think Apache Commons fileUpload will help you. 我认为Apache Commons fileUpload将为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.