0

I am working on a webapp using jsp and servlets and I want to populate a date to HTML field which has the input type "Date".

I am pretty sure that my java code is getting the value for the input field and when I checked the value from "Inspect element" in browser, it shows that the value as expected. But the values are not visible in the field itself.

enter image description here

This is my jsp page's related field.

<input type="date" id="FeeStartDate" name="FeeStartDate" value = "'<%=Validation.formatDateForDateField(User.getFeeEndDate()) %>'">

As per below picture, value is there but it is not shown in the field. Why is that ? Any help is greatly appreciated.

enter image description here

Ps : I have tried like this as well but same result.

<input type="date" id="FeeStartDate" name="FeeStartDate" value = '<%=Validation.formatDateForDateField(User.getFeeEndDate()) %>'>

If needed, this is the java method.

public static String formatDateForDateField(Date dDate)
{
    System.out.println("dDate 1 ==========> " + dDate);
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    System.out.println("dDate 2 ==========> " + sdf.format(dDate));
    return sdf.format(dDate);
}

Thanks in advance.

1
  • Hi, there is '' single quotes remove that .Also , try with yyyy-mm-dd format . Commented May 14, 2021 at 13:26

1 Answer 1

1

Go Through this once: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

Try This:

String date="2018-08-21"; //Format the date in this format

Date: <input type="date" name="date" value="<%=date%>">     //Using Expression tag

Date: <input type="date" name="date" value="2018-08-21">  // Plain value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.