*
The moose likes Servlets and the fly likes Parameter value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Parameter value" Watch "Parameter value" New topic
Author

Parameter value

Jonathan Chiu
Greenhorn

Joined: Aug 01, 2001
Posts: 9
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!!!
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
The equals() method actually compares contents. Use the equals method.
Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Jonathan Chiu
Greenhorn

Joined: Aug 01, 2001
Posts: 9
Hello,
it still doesn't work! Somehow the parameter being 'get' isn't empty, even though nothing was entered!
Thanks
Steve Snodgrass
Greenhorn

Joined: Jun 12, 2001
Posts: 27
How about if (aString.length() == 0) or something to that effect?
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
Try stringVar.equals("") ...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040


How about if (aString.length() == 0) or something to that effect?

make it....
if ( !aString | | aString.trim().length() == 0)
trim() removes any extra spaces in the front or end.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parameter value
 
Similar Threads
Enhanced Observer pattern ?
difference between parameter and arguments
Should EJB not return initialized objects?
can this be called mutable?
Urgent help still needed!