aspose file tools*
The moose likes Servlets and the fly likes .equals and request.getparameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark ".equals and request.getparameter" Watch ".equals and request.getparameter" New topic
Author

.equals and request.getparameter

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I wanted to know what would be the correct way of doing something like this



since .getPArameter doesnt put "" if the parameter is not found
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rajesh Khan wrote:

since .getPArameter doesnt put "" if the parameter is not found


Yes. if parameter returns null then you will be end up with an exception.
so you can do this since equals method dont throw exception if the argument is null, instead it returns false.
or

I always use later idiom. because some times you need to invoke a method on string_
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Thanks but it should be
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Rajesh Khan wrote:Thanks but it should be

Seetharaman's version is fine. It's a very common idiom. The point of using if(string_ != null && !string_.equals("")) is that the expression "short-circuits". If the first part is false it doesn't bother calculating the second part. So you can be sure that if it reaches the second part string_ is definitely not null.
 
wood burning stoves
 
subject: .equals and request.getparameter