Forums Register Login

Urgent help still needed!

+Pie Number of slices to send: Send

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!!!
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send

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
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


Reply locked
This thread has been viewed 541 times.
Similar Threads
Should EJB not return initialized objects?
Parameter value
Enhanced Observer pattern ?
Static method is implicitly final?
HashMap Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:18:52.