一般我们用
requestgetParameter(value);
来获得静态HTML输入的值然后不要忘记判断是否为空是否含有特殊字符等
还可以用
Enumeration paramNames=requestgetParameterNames();
while(paramNameshasMoreElements()){String paramName=(String)paramNamesnextElement();}
来收集<input type=text name=name/>中的name
但是我们每增加新的一行参数名同上一行一样那么我们将如何获得value的值?
这里我又去看书(servlet 和 JSP 核心编程极好的一本书该讲的都讲了读明白了它servlet/JSP也就可以说精通了)p页里面:getParameterValues()返回字符串数组然后我们用循环判断这个字符串数组的长度再就是获得值了:)
requestgetParameter(value);//这个最熟悉获得文本框的值
(Enumeration)requestgetParameterNames();//获得文本框的名字
(String[])requestgetParameterValues(paramName);//获得静态html页相同的参数(多次出现)的值
*************html 页 javascript 代码:
<script language=javascript>
function tbladdrow()
{
var i=linesrowslength;
var row = TableinsertRow(Tablerowslength);
var col = rowinsertCell();
colinnerHTML = <INPUT id=line[+i+][name] name=line+i+name SIZE=>;
col = rowinsertCell();
colinnerHTML = <INPUT id=line[+i+][name]name=line+i+name SIZE=>;
col = rowinsertCell();
colinnerHTML = <INPUT id=line[+i+][name] name=line+i+name SIZE=>;
col = rowinsertCell();
colinnerHTML = <INPUT id=line[+i+][name] name=line+i+name SIZE=>;
}
function tbladdrows(items)
{
for( i = ; i <= items ; i++)
{
tbladdrow();
}
}
function delrow()
{
if(linesrowslength==)
{
return false;
}
linesdeleteRow();
}
</script>
****************html页其它代码:
<html>
<head>
<meta httpequiv=ContentType content=text/html; charset=Big>
<title>输入</title>
</head>
<body>
<form action=getInputjsp>
<DIV align=center><FONT size=>输入测试</FONT></DIV></TD>
<TD width= bgColor=#eee>
<TABLE id=Table cellSpacing= borderColorDark=#ffffff cellPadding=
width= align=center borderColorLight=# border=>
<TBODY>
<TR bgColor=#>
<TH width=><FONT size=>参数一</FONT></TH>
<TH width=><FONT size=>参数二</FONT></TH>
<TH width=><FONT size=>参数三</FONT></TH>
<TH width=><FONT size=>参数四</FONT></TH></TR>
<TBODY id=lines name=lines><!
<TR>
<TD><INPUT id=things_name TYPE=text NAME=things_name SIZE=></TD>
<TD><INPUT id=things_model TYPE=text NAME=things_model SIZE=></TD>
<TD><INPUT id=things_number TYPE=text NAME=things_number SIZE=></TD>
<TD><input id=things_unit type=text name=things_unit size=></TD>
</TR>
></TBODY></TABLE>
<DIV align=center><BR></DIV>
<DIV align=center>
<INPUT id=items type=hidden value= name=items> <INPUT onclick=tbladdrow(itemsvalue);
type=button value=新增一行 name=insert/>
<font color=#eee> </font>
<INPUT language=javascript onclick=return delrow() type=button value=删除一行 name=del/>
</DIV></TD></TR></TBODY></TABLE>
<input type=submit value=commit/>
</form>
</body>
</html>
***jsp页收集输入
<%@ page contentType=text/html;charset=Big%>
<%@ page import=javautil*%>
<%
requestsetCharacterEncoding(big);
Enumeration paramNames=requestgetParameterNames();
String paramName=null;
while(paramNameshasMoreElements()){
paramName=(String)paramNamesnextElement();
String param=requestgetParameter(paramName);
//outprintln(paramName+ +param+<br>);
String paramValues[]=requestgetParameterValues(paramName);
for(int i=; i<=paramValueslength; i++)
{
outprintln(paramName+);
outprintln(paramValues[i]+<br>);}
}
//outprintln(<br>+name);
%>
<html>
<head>
<meta httpequiv=ContentType content=text/html; charset=Big>
<title>接受输入</title>
</head>
<body>
</body>
</html>