Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

validating jsp pages in servlet

843840May 13 2009 — edited May 14 2009
Hi 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.";
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2009
Added on May 13 2009
2 comments
143 views