This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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:
subject: Parameter value
Similar Threads
Should EJB not return initialized objects?
can this be called mutable?
difference between parameter and arguments
Urgent help still needed!
Enhanced Observer pattern ?