File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parameter value

 
Jonathan Chiu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • 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!!!
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equals() method actually compares contents. Use the equals method.
Bosun
 
Jonathan Chiu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
it still doesn't work! Somehow the parameter being 'get' isn't empty, even though nothing was entered!
Thanks
 
Steve Snodgrass
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if (aString.length() == 0) or something to that effect?
 
Manjunath Reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try stringVar.equals("") ...
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic