Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParameter == null

 
Jeff Dube
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice to see someone else using trim()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic