jsp+servlet循环插入一行后,怎么把所有数据添加到数据中?
循环插入代码为:<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%Stringpath=...
循环插入代码为:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript">
//动态增加行数
allCount=1
function addline()
{
document.getElementById('pro').style.display='block';
newRow=listtable.insertRow(listtable.rows.length);
newRow.ln=allCount;
newRow.id=allCount;
c1=newRow.insertCell(0);
c1.bgColor="#FFFFFF";
c1.innerHTML="<input size=10 id=pronameline name=pronameline"+allCount+">";
c2=newRow.insertCell(1);
c2.bgColor="#FFFFFF";
c2.innerHTML="<input size=10 name=pronum"+allCount+">";
c3=newRow.insertCell(2);
c3.bgColor="#FFFFFF";
c3.align="CENTER";
c3.innerHTML="<input type=checkbox value=t checked name=cPub"+allCount+">";
c4=newRow.insertCell(3);
c4.bgColor="#FFFFFF";
c4.align="CENTER";
c4.id="line"+allCount;
c4.innerHTML="<input type=button value=删除 onclick=delline(line"+allCount+")>";
allCount++
}
//删除行
function delline(lineid)
{
for(i=0;i<listtable.rows.length;i++)
{
for(j=0;j<listtable.rows[i].cells.length;j++)
{
if(listtable.rows[i].cells[j].id==lineid.id)
{
listtable.deleteRow(i);
return;
}
}
}
}
</script>
</head>
<body>
<div id="pro" >
<table border="0" cellpadding="0" cellspacing="0"
class="datalist" id="listtable">
<input type="button" name="save2" value="添加产品"
onclick="javascript:addline();" class="button"
onmouseover="this.className='button_mouseover'"
onmouseout="this.className='button'" />
<tr>
<th width="50" nowrap="nowrap">
产品名称
</th>
<th width="35" nowrap="nowrap">
数量
</th>
<th width="75" nowrap="nowrap">
--
</th>
<th width="60" nowrap="nowrap">
删除
</th>
<th width="61" nowrap="nowrap">
保存
</th>
</tr>
</table>
</form>
</div>
</body>
</html> 展开
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript">
//动态增加行数
allCount=1
function addline()
{
document.getElementById('pro').style.display='block';
newRow=listtable.insertRow(listtable.rows.length);
newRow.ln=allCount;
newRow.id=allCount;
c1=newRow.insertCell(0);
c1.bgColor="#FFFFFF";
c1.innerHTML="<input size=10 id=pronameline name=pronameline"+allCount+">";
c2=newRow.insertCell(1);
c2.bgColor="#FFFFFF";
c2.innerHTML="<input size=10 name=pronum"+allCount+">";
c3=newRow.insertCell(2);
c3.bgColor="#FFFFFF";
c3.align="CENTER";
c3.innerHTML="<input type=checkbox value=t checked name=cPub"+allCount+">";
c4=newRow.insertCell(3);
c4.bgColor="#FFFFFF";
c4.align="CENTER";
c4.id="line"+allCount;
c4.innerHTML="<input type=button value=删除 onclick=delline(line"+allCount+")>";
allCount++
}
//删除行
function delline(lineid)
{
for(i=0;i<listtable.rows.length;i++)
{
for(j=0;j<listtable.rows[i].cells.length;j++)
{
if(listtable.rows[i].cells[j].id==lineid.id)
{
listtable.deleteRow(i);
return;
}
}
}
}
</script>
</head>
<body>
<div id="pro" >
<table border="0" cellpadding="0" cellspacing="0"
class="datalist" id="listtable">
<input type="button" name="save2" value="添加产品"
onclick="javascript:addline();" class="button"
onmouseover="this.className='button_mouseover'"
onmouseout="this.className='button'" />
<tr>
<th width="50" nowrap="nowrap">
产品名称
</th>
<th width="35" nowrap="nowrap">
数量
</th>
<th width="75" nowrap="nowrap">
--
</th>
<th width="60" nowrap="nowrap">
删除
</th>
<th width="61" nowrap="nowrap">
保存
</th>
</tr>
</table>
</form>
</div>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询