File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes request.getParameter == null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameter == null" Watch "request.getParameter == null" New topic
Author

request.getParameter == null

Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Hi,
My form is validated by a jsp and i try to get the parameter of a field but i have a problem.
Here it is.
if (request.getParameter("BegDay") == null)
is not a valid way to check if the field is empty caus i always get outside the loop, even if the field is empty.
on the other hand:
if (request.getParameter("BegDay") == "")
is neither good
What is the way to check if the field is empty???
These fields are text field and my syntax is okay but i need to evaluate the content of the field. I cannot use javascript because this field is not an essentiel one so the user is free to enter data or not.
Thank you
Jeff
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5

if (request.getParameter("BegDay") == "")
Tch tch! You know you should never compare Strings with ==
Try this
String tmp = request.getParameter("BegDay");
if( tmp == null | | tmp.trim().length() == 0 ){
// no entry or just spaces
}
Bill

Java Resources at www.wbrogden.com
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Nice to see someone else using trim()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getParameter == null
 
Similar Threads
Any elegant way to check that field is not empty?
drop down boxes
jsp:setProperty is ignored !
Weird update vs insert vs select from DB
How to have checkbox value blank instead of "null"