| Author |
java.text.ParseException: Unparseable date: ""
|
JayaSiji Gopal
Ranch Hand
Joined: Sep 27, 2004
Posts: 303
|
|
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?
|
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
|
 |
Jyothish Divakar
Greenhorn
Joined: Feb 12, 2007
Posts: 10
|
|
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
Joined: Jan 18, 2008
Posts: 53
|
|
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
|
Qussay NAJJAR
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Qussay Najjar
Ranch Hand
Joined: Jan 18, 2008
Posts: 53
|
|
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
Joined: Jan 18, 2008
Posts: 53
|
|
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
|
 |
 |
|
|
subject: java.text.ParseException: Unparseable date: ""
|
|
|