I have aN HTML form where I have check boxes. In the Servlet, I am trying to print all the Parameter names with Values and In case it has no value i.e it's unchecked , print "BLANK", But surprisingly, the parameter itself is not printed if it has no value/is unchecked.Follows the code:
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.print("<tr><td>" + paramName + "</td>\n<td>");
String[] paramValues = request.getParameterValues(paramName);
if(paramValues.length == 0)
out.println("BLANK"); //Why does this not work?
// Read single valued data
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.println("<i>No Value</i>");
else
out.println(paramValue);
}
else {
// Read multiple valued data
out.println("<ul>");
for(int i=0; i < paramValues.length; i++) {
out.println("<li>" + paramValues[i]);
}
out.println("</ul>");
}
}
out.println("</tr>\n</table>\n</body></html>");
}