request.getParameterValues(Stringname)是获得如checkbox类(名字相同,但值有多个)的数据。接收数组变量,如checkobx类型
request.getParameter(Stringname)是获得相应名的数据,如果有重复的名,则返回第一个的值. 接收一般变量,如text类型
JSP中request.getParameterNames和getParameterValues应用
try...{
String name;
Enumeration pNames=request.getParameterNames();
while(pNames.hasMoreElements())...{
name=(String)pNames.nextElement();
out.print(name+"="+request.getParameter(name));
}
}catch(Exception e)...{
out.print(e.toString());
}
for (Enumeration iter = request.getParameterNames();iter.hasMoreElements();) ...{
String element = (String) iter.nextElement();
logger.debug("parameter:"+element);
logger.debug("value:"+request.getParameter(element));
}
String[]userId=request.getParameterValues("userId");