这是我读取复选框的代码,你可以替换成text,只能用html的标签,用Struts的html标签本人试了下没有做出来。
步骤是:
1、统计一共有多少记录,然后把记录数放在一个hidden项里面
2、在action里面循环,取出选择(你的就是文本框)的值
为什么是html而不是Struts的html,因为你的记录条数是不确定的,html:text的property的值是需要和struts-config.xml文件对应起来的。所以只能是动态的。jsp页面代码
--------------------
<% int i = -1; %>
<logic:present name="poweruser">
<logic:iterate id="puser" name="poweruser">
<% i += 1; %>
<TR class="tr">
<TD width="20%" align="center" height="24">
<INPUT type="checkbox" name="uselect<%=i%>" value="${puser.pk}">
</TD>
<TD width="80%" align="center">
<bean:write name="puser" property="username" />
</TD>
</TR>
</logic:iterate>
</logic:present>
<html:hidden property="userid" value="${ucount}"/>action代码:
--------------------------------------------
...
int ucount = Integer.valueOf(addSysModulePowerForm.getString("userid")).intValue();
for (int i = 0; i < ucount; i++){
//取值
String userid = request.getParameter("uselect"+i);}
自己再看看。。
步骤是:
1、统计一共有多少记录,然后把记录数放在一个hidden项里面
2、在action里面循环,取出选择(你的就是文本框)的值
为什么是html而不是Struts的html,因为你的记录条数是不确定的,html:text的property的值是需要和struts-config.xml文件对应起来的。所以只能是动态的。jsp页面代码
--------------------
<% int i = -1; %>
<logic:present name="poweruser">
<logic:iterate id="puser" name="poweruser">
<% i += 1; %>
<TR class="tr">
<TD width="20%" align="center" height="24">
<INPUT type="checkbox" name="uselect<%=i%>" value="${puser.pk}">
</TD>
<TD width="80%" align="center">
<bean:write name="puser" property="username" />
</TD>
</TR>
</logic:iterate>
</logic:present>
<html:hidden property="userid" value="${ucount}"/>action代码:
--------------------------------------------
...
int ucount = Integer.valueOf(addSysModulePowerForm.getString("userid")).intValue();
for (int i = 0; i < ucount; i++){
//取值
String userid = request.getParameter("uselect"+i);}
自己再看看。。
var aa = document.getElementsByName("name");
这里得到的aa是一个数组,通过aa[i].value可以取出里面的所有值,
然后把这些值加在一起,如:
var b;
for(i=0;i<aa.length;i++){
b+=(aa[i].value+|);
}
然后把b通过参数传到action里去,通过StringStoze。。把字符串分割为数组
这样就可以得到全部的值了