Oreilly多部分解析器和动态创建行(通过jquery)
Oreilly Multipart parser and dynamically created rows (through jquery)
我有2个jsp:createEdit.jsp和save.jsp
内createEdit.jsp我有一个html代码内的表单,因为它包括文件上传,我使用编码类型"multipart/form-data"。在表单中有一个表。需求是将数据从表保存到数据库。我可以通过Jquery或Javascript动态地向表中添加行。
这是我的示例表单表:
<form action="save.jsp" method="post" enctype="multipart/form-data" name="frm">
<table id="tblRating">
<tr><td><input id="e1">Element1</input><input id="e2"></input><td><tr>
</table>
</form>
用于向现有表动态添加行的javascript代码:
function generateRow(){
console.log("Generate the row");
var table = document.getElementById('tblRating');
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
console.log(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select":
newcell.childNodes[0].selectedIndex = 'null';
break;
}
}
return false;
}
在save.jsp我有一个脚本代码(代码是相当旧的,所以它有脚本)。它使用Oreilly Multipart解析器解析请求,并逐个获取输入元素。
save.jsp的示例代码:
MultipartParser parser = new MultipartParser(request, 2 * 1024 * 1024);
String e1Value = ((ParamPart) parser.readNextPart()).getStringValue()); //reads the input elements only
String e2Value = ((ParamPart) parser.readNextPart()).getStringValue());
问题是当我试图通过解析器读取元素时,它能够获得表单上的现有行。但是解析器不处理通过javascript创建的行。我试着在提交时打印表格。它包含动态创建的行。但是当我试图从解析器中获取数据时,它不提供通过javascript创建的行。
请帮助。
我会确保每个输入有一个唯一的name="…"属性通过附加行号和列号的名称(例如myInput_2_3将是第2行,第3列的输入)。你可以使用setAttribute('name',…)在你的newcell设置输入的名称。
我终于熬过去了。这个问题与多部分解析器无关。产生问题的是JSP的结构。由于现有的结构,jsp表单不能接受动态创建的元素。
早先的jsp结构是这样的:<table align=center border=0 cellpadding=0 cellspacing=0 width=75%>
<form onSubmit="return validate()" action=".." method="post" enctype="multipart/form-data" name="frmEntry">
<tr><td>........</td></tr>
</form>
</table>
上面的结构产生了问题。所以我把表格放到表格里面。
<form onSubmit="return validate()" action=".." method="post" enctype="multipart/form-data" name="frmEntry">
<table align=center border=0 cellpadding=0 cellspacing=0 width=75%>
<tr><td>........</td></tr>
</table>
</form>
它工作了:)
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 通过JQuery重定向到另一个页面
- 通过jquery设置最小高度
- 通过jQuery添加ng样式属性,angular不更新
- 我可以通过JQuery将CSS类交换为一个特殊的元素集吗
- 是否可以仅通过jQuery将图像替换为用户动态选择的另一个图像
- 如何通过JQuery修改样式属性
- 如何通过Jquery从具有相同名称但不同索引的输入中获取所有值
- 如何通过jQuery发送选定的元素和文本输入
- 通过Jquery根据下拉列表中的选择禁用数字字段
- 提交按钮通过JQuery和JavaScript函数所做的更改不会持续
- 通过jQuery插入HTML不起作用
- UIWebview赢得't通过基本身份验证加载动态加载的资源(通过jQuery mobile)
- 通过jQuery设置转换值
- 无法通过JQuery更改图像的src
- 通过jQuery函数将拉丁数字更改为波斯数字并添加逗号
- 通过JQuery将字符串转换为JSON
- 如何通过JQuery触发JS原生甚至addEventListener(“change”,函数)
- 通过Jquery更改html5中的视频(不同质量)文件
- 如何通过jQuery选中所有复选框并在单击一个复选框时取消选择