• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.text.ParseException: Unparseable date: ""

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text field in the jsp page. This field is supposed to have input of a date in the format MM/dd/YYYY

If the user does not input any date, i get the following exception:


I see that when there is no date entered, the condition in the if loop is satisified and the exception is thrown. what am i missing here?
 
Jyothish Divakar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it will get corrected if you give

if(value != null && !value.equalsIgnoreCase("")) {

since it was OR it will check for not null (!= null) and will enter the loop once is satisfied even if it is empty string ("") since it will not check for the second expression if it gets a true for the first expression. Also to stress a point it will be good to use constants first to avoid any null pointer exception in equalsIgnoreCase() like
!("".equalsIgnoreCase(value))
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JayaSiji,
In such cases the best way is using JavaScript and don't even let it go to process if the values are not as you want them.
check this thread:
JavaScript Example - Check Date Formation
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Qussay Najjar:
Hi JayaSiji,
In such cases the best way is using JavaScript and don't even let it go to process if the values are not as you want them.
check this thread:
JavaScript Example - Check Date Formation

Relying on Javascript alone is a very very bad idea, simply because the user can turn it off.
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:

Relying on Javascript alone is a very very bad idea, simply because the user can turn it off.

Yes, you're completely right, I've almost forgot.
So JavaScript can be the first line to check, and in the servlet you can use
something like this:


Hope it helps..
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Qussay Najjar:



It should be:
Pattern datePattern = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{4})");//pattern with the form dd/mm/yyyy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic