• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parameter value

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equals() method actually compares contents. Use the equals method.
Bosun
 
Jonathan Chiu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about if (aString.length() == 0) or something to that effect?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try stringVar.equals("") ...
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic