This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes .equals and request.getparameter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply 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: 3862
    
    1

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: .equals and request.getparameter
 
Similar Threads
Jsp---blank fields
Servlet Displays Old DB Entries
nullpointerexception
redirecting page in JSP
Body onload method