我正在根据DB的输入创建一个表,并将其显示在我的div中,如下所示:
的Servlet
out.print("<table id=prev class=display nowrap stripe row-border order-column>");
out.print("<thead>");
out.print("<tr>" +
"<th>Form Id</th>\n" +
" <th>Form Name</th>\n" +
" <th>Open</th>\n" +
" <th>Report</th>\n" +
" <th>View</th>\n" +
" <th>Insert</th>\n" +
" <th>Update</th>\n" +
" <th>Delete</th>\n" +
" <th>Approve Transaction</th>\n" +
" <th>Reject Transaction</th>\n" +
" </tr>");
out.print("</thead>");
out.print("<tfoot>");
out.print("<tr>" +
"<th>Form Id</th>\n" +
" <th>Form Name</th>\n" +
" <th>Open</th>\n" +
" <th>Report</th>\n" +
" <th>View</th>\n" +
" <th>Insert</th>\n" +
" <th>Update</th>\n" +
" <th>Delete</th>\n" +
" <th>Approve Transaction</th>\n" +
" <th>Reject Transaction</th>\n" +
" </tr>");
out.print("</tfoot>");
out.println("<tbody>");
while(rs1.next())
{out.print("<tr><td name=prvlg>"+rs1.getInt("FORM_ID")+"</td>"
+ "<td name=prvlg>"+rs1.getString("FORM_NAME")+"</td>");
if(form1==1){ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(report==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(view==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(insert1==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(update==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(delete==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(isapproved==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
if(not_approved==1)
{ out.print("<td name=prvlg><input type=checkbox checked=checked></td>");}
else { out.print("<td name=prvlg><input type=checkbox></td>");}
}
out.print("</tbody></table>");
}
并将其显示为:
if ((zreq.readyState == 4) && (zreq.status == 200)) {
document.getElementById("user_prev").innerHTML = zreq.responseText;
$("#parent").DataTable({
dom: 't',
});
和div在表单内。提交时,所有其他信息都已提交,但表格内容除外。
String td[]=request.getParameterValues("prvlg");
它始终为null。有谁能建议我哪里出错?
答案 0 :(得分:1)
表单字段(input,textarea,select,..)应该有name
属性我要提交。
如下的行:
<input type=checkbox checked=checked>
应该是这样的:
<input name=parameterName type=checkbox checked=checked>
然后在服务器上,您可以使用以下命令访问此参数:
request.getParameter("parameterName");
您已在name
- 标记上设置td
属性:
<td name=prvlg>
但只提交表单元素。
编辑:
为了提交其他值,它们也应该在input
中
您还想提交前两行:
{out.print("<tr><td name=prvlg>"+rs1.getInt("FORM_ID")+"</td>"
+ "<td name=prvlg>"+rs1.getString("FORM_NAME")+"</td>");
然后在表格单元格中添加隐藏的输入:
{out.print("<tr><td name=prvlg><input name='formId' type='hidden' value='" + rs1.getInt("FORM_ID") + "'></td>"
+ "<td name=prvlg><input name='formName' type='hidden' value='" + rs1.getString("FORM_NAME") + "'></td>");
<input type=hidden>
在浏览器中不可见,但已提交。