简体   繁体   English

自动填写注册表单字段

[英]Auto fill registration form fields

I have a jsp page for registration form where there are 2 fields regDate and endDate.我有一个用于注册表单的 jsp 页面,其中有 2 个字段 regDate 和 endDate。 RegDate is today's date and endDate is one year after today. RegDate 是今天的日期,而 endDate 是今天之后的一年。 Now I want to auto fill these fields in my jsp to store them In MySQL database.现在我想在我的 jsp 中自动填充这些字段以将它们存储在 MySQL 数据库中。 I'm using annotation based spring mvc and hibernate jpa annotations spring data etc我正在使用基于注释的 spring mvc 和 hibernate jpa 注释 spring 数据等

For an HTML text field, you can to supply a string representation of a date to the element's value attribute.对于 HTML 文本字段,您可以为元素的value属性提供日期的字符串表示形式。 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.要获取当前日期,请调用java.util.Calendar.getInstance()并使用生成的CalendargetTime()方法(该方法返回java.util.Date对象)来确定 regDate。 Increase the Calendar 's year with add(Calendar.YEAR, 1) and get another Date for next year's date.使用add(Calendar.YEAR, 1)增加Calendar的年份,并为下一年的日期获取另一个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()+"\"" %> />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM