Bookmark Topic Watch Topic
  • New Topic

Urgent help still needed!

 
Jonathan Chiu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator

Hello,
This is the situation:
I have an interface for people to enter various information. Then the details are passed on to a
servlet for further implementation. I want to give people an option not to fill in several fields.
So, in my servlet to start off:
String aString = req.getParameter("aName");
Then using the content of "aName" for another method:
aMethod(aString);
Problem: I implemented an if-statement so that if the user did not type in anything in "aName" then
skip the method aMethod(). But I have tried:
if(aString != null)
{
aMethod(aString)
}
also
if(aString != "")
{
aMethod(aString)
}
Both of them didn't work, ie, it simply return true and the method was still being called. What is in
that empty String when the Parameter didn't contain any value???
Please give me some suggestions!!!
Thanks so much!!!
 
Heath Lilley
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Report post to moderator
To test for a value in a string you must use the .equals() method...
when you say str != "" or str == "" you are asking if the object "reference" points to "" (the empty string). The only time you should use == or != is to test for null.
To properly test to see if a reqest parameter is null try the following:

hope this helps.
Heath
[This message has been edited by Heath Lilley (edited August 24, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Report post to moderator

Please DONOT post the same message twice
(and that too with a subject Urgent).
Chk out your other msg for other replies,
I just suggeted a method there.... http://www.javaranch.com/ubb/Forum7/HTML/005602.html
Thanks. <not so happy>
- satya
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!