解决Error:ftl页面通过form提交表单,后台java类接收的值为null
来源:互联网 发布:移动端优化 编辑:程序博客网 时间:2024/04/29 08:34
错误描述:
checkoutdetail.ftl页面:用Js中的Ajax方式提交form表单,CheckOutDetailWork.java中元素的值为空。
checkoutdetail.ftl提交表单部分代码:
<script>$(function(){ $('#submit-order').click(function(){ //通过标签的名字获取元素列表//var obj = document.getElementsByTagName("input"); //通过元素的名字获取元素group1的列表var obj = document.getElementsByName("group1"); for(var i=0; i < obj.length; i++){ //逐个验证是否被选中 if(obj[i].checked){ //被选中的值 //alert(obj[i].value); //若选中,就获取空间value的属性值 var checked = obj[i].value; //通过value的属性值,到switch语句中设置隐藏域的值(选中为1,未选中为0) switch(checked){ case "free":free = "1";continue; case "local":local = "1";continue; }}else{ var checked = obj[i].value; switch(checked){ case "free":free = "0";continue; case "local":local = "0";continue; }}}//通过元素的名字获取元素group2的列表var obj = document.getElementsByName("group2"); for(var i=0; i<obj.length; i++){ //选中为1,未选中为0 if(obj[i].checked){ var checked = obj[i].value; switch(checked){ case "bankCard":bankCard = "1";continue; case "alipay":alipay = "1";continue; case "weChat":weChat = "1";continue; case "direct":direct = "1";continue; }}else{ var unchecked = obj[i].value; switch(unchecked){ case "bankCard":bankCard = "0";continue; case "alipay":alipay = "0";continue; case "weChat":weChat = "0";continue; case "direct":direct = "0";continue; }}} $.ajax({ type: "POST", url: '<@ofbizUrl>submitorder</@ofbizUrl>', data: $('#submitorder').serialize(), dataType: "json", success: function(result){if(result.code===1){ }} }); });});</script>
CheckOutDetailWork.java接收页面提交的值,部分代码
String group1 = request.getParameter("group1");
解决办法:
查看checkoutdetail.ftl页面,发现
<div class="radio-group"><span style="white-space:pre"></span><input id="free" class="le-radio" type="radio" <span style="color:#ff0000;">name="group1"</span> value="free"> <div class="radio-label bold">免运费</div><br> <!-- 隐藏域传值,默认为非选中状态 --> <input type="hidden" id="free" name="free" value="0"> <input id="local" class="le-radio" type="radio" <span style="color:#ff0000;">name="group1"</span> value="local" checked> <div class="radio-label">快递<br><span class="bold">$15</span></div> <input type="hidden" id="local" name="local" value="1"></div>
注意:form千万不能嵌套!!!
0 0
- 解决Error:ftl页面通过form提交表单,后台java类接收的值为null
- struts2 form提交表单自动封装对象,后台取值为null的几个原因
- 页面ajax提交form 表单 以及后台接收
- 使用serialize()提交form表单数据后台为null问题解决
- 通过form的action属性提交表单并接收处理返回值的方法(页面不跳转)
- form表单提交get请求,后台接收乱码的解决方案
- Action如何接收jsp页面form表单提交的数据?
- Action如何接收jsp页面form表单提交的数据?
- easyui 里 table 的 form提交后台获取的值全为null
- 如何通过submit提交form表单获取后台传来的返回值
- form表单提交到myeclipse10下的Tomcat后台,为什么值为空
- SpringMVC下ajax提交form表单与后台接收
- net接收ajax提交form的表单
- go语言form表单提交以及后台如何接收并返回做一个简单的解释
- springmvc用实体类接收form表单提交多个name相同的input的值
- Ajax向java后台中传值为数组时,后台接收不到(为null)的问题
- Ajax向java后台中传值为数组时,后台接收不到(为null)的问题
- 解决form表单重复提交以及多页面提交问题
- 解决360浏览器优先选择极速模式,在兼容模式下出现乱码问题
- 手机APP自动化测试简单录制
- Android 自定义加载框dialog
- jQuery工具函数
- mysql 规范
- 解决Error:ftl页面通过form提交表单,后台java类接收的值为null
- 线程池
- Install liblinear on Mac OSX
- 机器学习(二):分类算法之k-近邻算法
- 概率算法
- (并查集第一课) 冗余关系 - 树/森林
- Java线程(四):线程中断、线程让步、线程睡眠、线程合并
- Android 自定义 declare-styleable 的format
- MySQL学习笔记--安装配置(RPM)