Html 获取复选框组的值
我有一个表单,其中包含Html 获取复选框组的值,html,jsp,servlets,checkbox,Html,Jsp,Servlets,Checkbox,我有一个表单,其中包含无线电组和复选框组,每个复选框组/无线电组都有一个唯一的名称 在我的Servlet中,我尝试获取那些无线电组和复选框组的所有选中值 PrintWriter out = response.getWriter(); Enumeration<String> requestParameters = request.getParameterNames(); while (requestParameters.hasMoreElements()) { String
无线电组
和复选框组
,每个复选框组
/无线电组
都有一个唯一的名称
在我的Servlet
中,我尝试获取那些无线电组
和复选框组
的所有选中值
PrintWriter out = response.getWriter();
Enumeration<String> requestParameters = request.getParameterNames();
while (requestParameters.hasMoreElements()) {
String paramName = (String) requestParameters.nextElement();
out.println("Request Paramter Name: " + paramName
+ ", Value - " + request.getParameter(paramName));
}
我检查了最后三个复选框,只得到一个值,如下所示:
请求参数名称:问题1,值-编译
我在谷歌上搜索了一下,发现我必须在每个复选框组的名称后添加一个[]
,但当我尝试这样做时,我得到的是:
请求参数名称:问题1[],值-编译数据
如何解决此问题?选中表单中的多个复选框将为您提供字符串数组形式的值。您必须使用inor来获取在字符串数组中选择的所有值
您的样本可能是:
String[] questions = request.getParameterValues("question_1");
for(int i=0;i<questions.length;i++){
out.println(questions[i]);
}
String[]questions=request.getParameterValues(“问题1”);
对于(int i=0;i
String[] questions = request.getParameterValues("question_1");
for(int i=0;i<questions.length;i++){
out.println(questions[i]);
}