JSP中如何从一行的多个文本框,提取文本框的输入内容,然后放到一个数组进行传递?

<body>
<%
int i=1;
int j=1;
%>
<%
int time[]={1,2,3,4,5,6,7,8,9,10,11};
%>
<form id=form1 action="js" method="post" >
<table border="1">
<tr>
<td>时段</td>
<% for(i=0;i<11;i++)
{ %>
<td ><%=time[i] %></td>
<% } %>
</tr>
<tr>
<td>预测量</td>
<% for(i=0;i<11;i++)
{ %>
<td height=8><input type="text" name=ycl style="width:60px"></td>
<% } %>
</tr>

<tr>
<td>合同量</td>
<% for(i=0;i<11;i++)
{ %>
<td height=8><input type="text" name=htl style="width:60px"></td>
<% } %>
</tr>
</table>
<input type="submit" value="确定">
</form>
</body>
我想要做的是把循环输出的预测量跟合同量这两行里面的文本内容分别提取放到数组里,再提交给servlet 进行相应的计算,本人是这方面的小白,求高手指导,可加QQ:761706897 非常感谢~

如果是这样,不如在程序阶段就把格式做好,然后一次性传给jsp显示

具体做法,遍历你的ResultSet,然后用stringBuffer 把所有的名字连起来

不过记得中间加逗号

然后就是以String的方式 传到jsp上,设置个request属性即可!

希望能帮到你,你的分也能帮到我
另外,虚机团上产品团购,超级便宜
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-06-03
<tr>
<td>预测量</td>
<% for(i=0;i<11;i++)
{ %>
<td height=8><input type="text" name="ycl_<%=i%>" style="width:60px"></td>
<% } %>
</tr>

<tr>
<td>合同量</td>
<% for(i=0;i<11;i++)
{ %>
<td height=8><input type="text" name="htl_<%=i%>" style="width:60px"></td>
<% } %>
</tr>

改一下文本框的name值,这样就可以把每个文本框的name值设置的不一样了。 你可以查看下源文件代码应该是这样的:
<td height=8><input type="text" name="ycl_0" style="width:60px"></td>
<td height=8><input type="text" name="ycl_1" style="width:60px"></td> .......

然后在servlet里面可以这么写
String ycl[] = new ycl[11]; //定义预测量数组
String hcl[] = new hcl[11]; // 合同量
for (int i = 0; i < 11; i++)
{
ycl[i] = request.getParameter("ycl_" + i); // 获取jsp页面的预测量文本框值赋值给预测量数组
hcl[i] = request.getParameter("hcl_" + i); // 合同量
}本回答被提问者采纳
第2个回答  2011-05-06
100
第3个回答  2011-05-05
建议不要使用java小脚本
第4个回答  2011-05-05
岁月无声,597966319
相似回答