Auto fill registration form fields

Auto fill registration form fields



I have a jsp page for registration form where there are 2 fields regDate and endDate. RegDate is today’s date and endDate is one year after today. Now I want to auto fill these fields in my jsp to store them In MySQL database. I’m using annotation based spring mvc and hibernate jpa annotations spring data etc





What is the specific problem you're facing? Could you please share the code that you've tried so far?
– crizzis
Aug 22 at 21:33





Those values can be passed from the controller to the view (JSP page) as model parameters. Please review the Spring MVC documentation for details on passing model parameters from controllers to views.
– manish
Aug 23 at 6:13




1 Answer
1



For an HTML text field, you can to supply a string representation of a date to the element’s value attribute. To get the current date, call java.util.Calendar.getInstance() and use the resulting Calendar’s getTime() method, which returns a java.util.Date object, to determine regDate. Increase the Calendar’s year with add(Calendar.YEAR, 1) and get another Date for next year’s date.


value


java.util.Calendar.getInstance()


Calendar


getTime()


java.util.Date


Calendar


add(Calendar.YEAR, 1)


Date



Edit: I had broken code before, but this should work.


<%@ page import = "java.util.Calendar" %>
<%@ page import = "java.util.Date" %>
<%! public Calendar cal = Calendar.getInstance(); %>



And later in the page:


<input type="text" name="regDate" value=<%= """+cal.getTime()+""" %> />
<% cal.add(Calendar.YEAR, 1); %>
<input type="text" name="endDate" value=<%= """+cal.getTime()+""" %> />





Now i am getting error as "Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endDate'"
– Shivani Deshmukh
Aug 23 at 18:51





I actually did a bunch of dumb things in my answer; I’ll edit it once I have code that runs.
– Gregory Gan
Aug 24 at 19:33





I have edited the answer to include code that works based on my interpretation of your question. If you think I interpreted it wrong or it still doesn’t work for you, please explain a bit more about your problem.
– Gregory Gan
Aug 24 at 19:44






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)