In my application i have one textfield which maps to date in action class. If i entered 15/12/2011 (MM/dd/yyyy) it automatically converts it to 03/12/2012(MM/dd/yyyy).
My code is :
jsp Page :
<s:textfield name="drDt" id="drDt" />
Action class:
private Date drDt;
public Date getDrDt() {
return drDt;
}
public void setDrDt(Date drDt) {
this.drDt = drDt;
}
Problem is with code :
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.parse(dateValue);
above statement has some problem.
This is the “default” behaviour. Otherwise, set
dateFormat.setLenient()tofalse. Setting that tofalsewill throwExceptionupon encountering invalid date like the one in your example. You need to handle that gracefully. Perhaps, show a message to the user that the date entered is not correct or invalid. Precisely, add validator to validate user inputs.