Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 6th, 2001, 11:04 AM
Rachelmnms Rachelmnms is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Seattle, WA
Posts: 18 Rachelmnms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy 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

Reply With Quote
  #2  
Old December 6th, 2001, 08:05 PM
Lord MJ Lord MJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Posts: 34 Lord MJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 2 sec
Reputation Power: 7
Send a message via AIM to Lord MJ Send a message via Yahoo to Lord MJ
Quote:
if ( Name == "" && Age == "")
{
error handler . . .
}else{
do what I want . .
}


Strings are objects, pointers, not primatives you have to say if(Name.equals("") && Age.equals(""))
{
error handler . . .
}else{
do what I want . .
}

Reply With Quote
  #3  
Old December 7th, 2001, 08:02 AM
Rachelmnms Rachelmnms is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Seattle, WA
Posts: 18 Rachelmnms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Perfect!

Thanks! That was the ticket . . I'm going to read that chapter on ==, != again.

Rachel

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > When null isn't null or "" or ??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway