我是struts的新手。我正在使用jquery datepicker插件。我想从用户那里获取日期(和时间)并将其插入数据库。当我提交表单时,如果我将数据类型设置为long(或int),则动作类接收0值,并且当我将数据类型设置为其他任何内容时它接收null。我不确定应该使用什么数据类型以及如何完成它。请帮忙
JSP表格
<s:form name="register-complaint" action="registerComplaint" method="post">
:
:
<sj:datepicker id="date_time" name='date_and_time' label="Date and Time of Offence"
timepicker="true" timepickerAaPm="true" timepickerGridHour="1" timepickerGridMinute="5"
timepickerStepMinute="5"/>
:
:
</s:form>
动作类
private Date dateAndTimeOfOccurance;
// or long
public String execute throws Exception{
:
ps.setDate(13, (java.sql.Date) getDateAndTimeOfOccurance());
// or ps.setLong(13, getDateAndTimeOfOccurance());
:
}
答案 0 :(得分:0)
您的name
属性错误。因为你的变量是
private Date dateAndTimeOfOccurance;
你需要在JSP中编写它:
<sj:datepicker name = "dateAndTimeOfOccurance"
id = "date_time"
label = "Date and Time of Offence"
timepicker = "true"
timepickerAaPm = "true"
timepickerGridHour = "1"
timepickerGridMinute = "5"
timepickerStepMinute = "5"/>
显然要记住在Action中为该变量生成一个Getter和一个Setter。