JSP and Forms: if a field is empty
Hi. I have the following code that gets the input names and their values from a form that is to be sent to my email. This is working fine.
Code:
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramValue = request.getParameter(paramName);
message.println(paramName + ": " + paramValue);
}
Then, when submitting the form, I want to leave out the fields that are empty, so I added an IF statement to the above:
Code:
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramValue = request.getParameter(paramName);
if (paramValue != null) {
message.println(paramName + ": " + paramValue);
}
}
But the IF loop doesn't work and don't know why. I appreciate if anyone could help me with this.
Thanks in advance
Atrisa