JSP页面,动态表单的复选框传值问题

有两个页面A.jsp,B.jsp,A.jsp是显示的,内容是从数据库中查出的数据,做了个一个表单,记录是动态生成,每条记录前都有一个复选框,然后在点击“提交”按钮的时候,需要将A.jsp已经被打“√”的记录传递到页面B.jsp中,然后在B.jsp中得到这些记录并进行数据库的插入操作。
A.jsp:建立一个form表单,
<form action="B.jsp" mgethod="post" name="form1" >
<div id="Layer5" style="position:absolute; width:100%; height:304px; z-index:3; left: 0px; top: 43px;">
<div id="Layer1" style="position:absolute; width:100%; height:261px; left: 0px; top: 0px; overflow: auto; visibility: visible;">
<table width="97%" border="1" bordercolor="#FFFFFF">
<%
while(rs.next())
{
i++;
a1=rs.getString(1).trim();
a2=rs.getString(2).trim();
a3=rs.getString(3).trim();

%>
<tr bordercolor="#004080">
<td width="5%" nowrap>
<div align="center" class="style4 style7 style8"><%=i%></div></td>
<td width="8%"><div align="center">
<input name="checkbox231" type="checkbox" value="1" checked>
</div></td>
<td width="52%" >
<div align="left" class="style4"><%=a1%></div></td>
<td width="14%" nowrap>
<div align="center" class="style8"><%=a2%>
</div></td>
<td width="14%" nowrap>
<div align="right" class="style4">
<p align="center"><%=a3%></p>
</div></td>
</tr>
<%}
rs.close();%>
</table>
</div>
<div id="Layer2" style="position:absolute; width:100%; height:35px; z-index:5; top: 268px;">
<table width="100%">
<tr>
<td><div align="center">
<input name="Submit" type="submit" class="style8" value=" 提交 ">
</div></td>
<td><div align="center">
<input name="Submit2" type="reset" class="style8" value=" 清空 ">
</div></td>
</tr>
</table>
</div>
</div>
</form>
然后在B页面中怎么得到A页面传递的数值,并将A页面中的a1,a2,a3的值传递到B页面的b1,b2,b3中,
是有很多条a1a2a3的记录,我用的是页面直接打开数据库的方式,
请问A页面我需要怎么改,然后在B页面怎么得到这些记录并写到数据库中,初学者,请给个详细的代码,可用后再追加

String getParameter(String name) 取得表单中指定名字的表单项值
String[] getParameterValues(String name) 取得表单中指定名字的表单项的所有值

下面附带一个例子:
//index.html
<html>
<head>
<title>测试Servlet页面</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>

<body>
<FORM name="form1" action="MyServlet" method="POST">
请输入姓名:
<INPUT name="name" type="text">
<INPUT name="submit" value="提交" type="submit">
</FORM>
</body>
</html>

//MyServlet.java
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {

public MyServlet() {//构造函数
super();
}

public void destroy() {//销毁时将调用的方法
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

//处理以GET方式提交过来的表单数据
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);//直接调用doPost方法
}

//处理以Post方式提交上来的表单数据
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
response.setCharacterEncoding("gb2312");//设置响应采用的编码方式
String name = request.getParameter("name");//从提交上来的表单中取name文本框的值
name = new String(name.getBytes("ISO8859-1"),"gb2312");//将字符编码转换为gb2312
PrintWriter out = response.getWriter();
ServletContext context = getServletContext();//得到整个Web应用的ServletContext对象
int count = 1;//从1开始起计
if (context.getAttribute("count")==null){//如果是第一位访客
context.setAttribute("count",new Integer(count));//设置计数器初始值
}else{//如果不是第一位访客
count = Integer.parseInt(context.getAttribute("count").toString());//取出现有的计数值
count++;//计数加1
context.setAttribute("count",new Integer(count));//更新计数器内容
}
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println(name+", 你好!你是第"+count+"位访客!");//实现简单问好
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

//本Servlet装载到容器后将自动执行的初始化方法
public void init() throws ServletException {
// Put your code here
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-10-15
A.jsp:
提交到form时将a1,a2的值传过去
<form action="B.jsp?a1=<%a1%>&a2=<%a2%>&a3=<%a3%>" mgethod="post" name="form1" >

这样写相当于是将a1的值以("a1",a1)的map形式存放在request中,a2、a3相同,然后再B.jsp就可以从请求中直接获取了。

B.jsp:
<%
String Ba1 = (String)request.getParameter('a1');
%>
这样就可以取得到前一个页面传过来到值了,同理 a2,a3在A.jsp和B.jsp中写法相同,试试先本回答被提问者采纳
第2个回答  2010-10-21
懂得数据库的增删查改吗?懂得主键吗?知道这些就很容易了,A页面从数据库查询的内容每条记录都有一个主键,把主键作为参数传到B页面,然后B页面拿到后去数据库查到该数据,然后把每一个字段取出来,插入你想插入的表,如果你懂JAVABEAN那就更简单了。
第3个回答  2010-10-15
getParameter()
相似回答