• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.text.ParseException: Unparseable date: ""

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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))
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic