|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Quote:
Strings are objects, pointers, not primatives you have to say if(Name.equals("") && Age.equals("")) { error handler . . . }else{ do what I want . . } |
|
#3
|
|||
|
|||
|
Thanks! That was the ticket . . I'm going to read that chapter on ==, != again.
Rachel |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > When null isn't null or "" or ?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|