<html> <head>
<title>设备列表</title>
<style type="text/css">
<!--
input{width:60px;}-->
</style>
<script language="javascript">
function checkbox(){
}
</script>
</head>
<body>
<%@ include file="admintop.jsp" %>
<form name="tianjia" action="Produce_servlet" method="post">
<hr width="100%"></hr><br>
<table align="center" width="80%" cellspacing="1" bgcolor="black">
<tr bgcolor="white" >
<td align="right" >
<input type="button" name="actionButton" value="操作" onClick="do_action()"></td>
</tr>
</table >
<%
Vector<String []> product = DBUtil.getProduces();
int color=0;//改变每行颜色
%>
<table align="center" width="80%" cellspacing="1" bgcolor="black">
<tr bgcolor="white">
<th>产品种类</th> <th>产品厂家</th>
<th>产品名称</th>
<th>选择</th>
</tr>
<tr bgcolor="white">
<%
for(String []s:product)
{
%>
<tr bgcolor=<%= color%2==0?"f7fbb9":"ffeeee" %>>
<td align="center">
<%=s[0]%>
</td>
<td align="center">
<%= s[1] %>
</td>
<td align="center">
<%= s[2] %>
</td>
<td align="center">
<input name="box" type="checkbox" value="checkbox" onclick="checkonebox()"/>
</td>
<%
color++;
}
%>
</tr>
</table >
</form>
</body>
</html>
s[0],s[1],s[2]是从一个数据库里面取出的内容,选中复选框后将该部分的内容保存到另外一个数据库选中后提交,
s[0],s[1],s[2]的内容就可以保存到一个数据库里面了
<title>设备列表</title>
<style type="text/css">
<!--
input{width:60px;}-->
</style>
<script language="javascript">
function checkbox(){
}
</script>
</head>
<body>
<%@ include file="admintop.jsp" %>
<form name="tianjia" action="Produce_servlet" method="post">
<hr width="100%"></hr><br>
<table align="center" width="80%" cellspacing="1" bgcolor="black">
<tr bgcolor="white" >
<td align="right" >
<input type="button" name="actionButton" value="操作" onClick="do_action()"></td>
</tr>
</table >
<%
Vector<String []> product = DBUtil.getProduces();
int color=0;//改变每行颜色
%>
<table align="center" width="80%" cellspacing="1" bgcolor="black">
<tr bgcolor="white">
<th>产品种类</th> <th>产品厂家</th>
<th>产品名称</th>
<th>选择</th>
</tr>
<tr bgcolor="white">
<%
for(String []s:product)
{
%>
<tr bgcolor=<%= color%2==0?"f7fbb9":"ffeeee" %>>
<td align="center">
<%=s[0]%>
</td>
<td align="center">
<%= s[1] %>
</td>
<td align="center">
<%= s[2] %>
</td>
<td align="center">
<input name="box" type="checkbox" value="checkbox" onclick="checkonebox()"/>
</td>
<%
color++;
}
%>
</tr>
</table >
</form>
</body>
</html>
s[0],s[1],s[2]是从一个数据库里面取出的内容,选中复选框后将该部分的内容保存到另外一个数据库选中后提交,
s[0],s[1],s[2]的内容就可以保存到一个数据库里面了
checked="checked";
}
这样可以将内容选上
if(action.equals("do_action")){
String product_type = req.getParameter("");
String product_factory = req.getParameter("");
String product_name = req.getParameter("");
String sql="insert into choseProduces(product_type,product_factory,product_name)values('"+product_type+"','"+product_factory+"','"+product_name+"')";
DBUtil.update(sql);
}
<input type="hidden" name="s" value=<%=s[0]%>> <%=s[0]%>
<input type="hidden" name="s" value=<%=s[1]%>> <%=s[1]%>
<input type="hidden" name="s" value=<%=s[2]%>> <%=s[2]%>
这样他们就是form里面的s的一个数组了,你在你的Produce_servlet里面在读取form中的s就能读到了
if(checked="checked")
document.check.submit();
}
function do_action(){
document.do_action.submit();
}
这样写行吗?
这样肯定不行
function check(){
if(checked="checked")
document.forms[0].submit();
}
}
function do_action(){
document.forms[0].submit();
}
sevlet里面doPost方法
if(action.equals("do_action")){
String product_type = req.getParameter("s[0]");
String product_factory = req.getParameter("s[1]");
String product_name = req.getParameter("s[2]");
String s[] ={product_type,product_factory,product_name};
for(int i=0;i<s.length;i++){
String sql="insert into choseProduces(product_type,product_factory,product_name)values('"+product_type+"','"+product_factory+"','"+product_name+"')";
DBUtil.update(sql);
}
}行吗?