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

Parameter value

Jonathan Chiu

Joined: Aug 01, 2001
Posts: 9
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:
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)
if(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.

So much trouble in the world -- Bob Marley
Jonathan Chiu

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

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
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!