validating jsp pages in servlet
843840May 13 2009 — edited May 14 2009Hi guys.
I need to validate fields from jsp page. This is the way I did it and would like to know from you guys who are more experienced than I, if it's the right way to do it. Please suggest better ways to do this, I'm new to this. Your help would be greatly appreciatted.
{
Enumeration paramList = request.getParameterNames();
//check for unfilled entries by looping through all fields in the request of the jsp page
while (paramList.hasMoreElements())
{
String paramName = paramList.nextElement().toString().trim();
String paramValue = request.getParameter(paramName).trim();
//Validate that fields are not empty;
if ((paramValue.length() <= 0) || (paramValue == null))
{
errors = paramName + " Is Blank. Please Ensure Its Filled In.";
isValid = false;
break;
}
}
I thought that I I have more than 10 fields using the method below would not be as good:
{
String fieldName = request.getParameter("ffieldName").toString();
if (fieldName.length <= 0 )
{
errors = fieldName + " Is Blank. Please Ensure Its Filled In.";
}
}