
December 6th, 2001, 11:04 AM
|
|
Junior Member
|
|
Join Date: Oct 2001
Location: Seattle, WA
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
When null isn't null or "" or ??
OK . . I first searched the forum for an answer and didn't find one. I did find something close, but it didn't change matters. Here's my problem, besides being new at this servlet stuff:
A page with a form that has two fields (name and age) get submitted with the submit button. I have code that looks like this:
String Name = null;
String Age = null;
Name = request.getParameter("Name");
Age = request.getParameter("Age");
etc.....
then I check to see if the fields had anything in them like this:
if ( Name == null && Age == null)
{
error handler . . .
}else{
do what I want . .
}
Problem here is if they don't enter a Name and Age it does "do what I want . . " when in fact it should do "error handler". WHY? Why isn't null not null in this case? The example I found said to init the Name and Age fields to "" then check the request.getParameter("Name") & request.getParameter("Age") for null first. Did that . . by init'ing the fields to "" they get instan'd, so you'd think something like:
if ( Name == "" && Age == "")
{
error handler . . .
}else{
do what I want . .
}
would trigger the error handler, right? Nope . . it doesn't. The only thing I've found to work so far is checking the field.length == 0. This works . . so, back to my question . . When is Null not Null but something entirely different? Any help, clue, link, article, psycho hotline number, ANYTHING would be much appreciated. Thanks
Rachel
|