Struts2 jquery datepicker将0或null值传递给action类 [英] Struts2 jquery datepicker passing 0 or null value to action class
本文介绍了Struts2 jquery datepicker将0或null值传递给action类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JSP表单
< s:form name =register-complaintaction =registerComplaintmethod =post>
:
:
< sj:datepicker id =date_timename ='date_and_time'label =违规的日期和时间
timepicker =truetimepickerAaPm = truetimepickerGridHour =1timepickerGridMinute =5
timepickerStepMinute =5/>
:
:
< / s:form>
动作类
private Date dateAndTimeOfOccurance;
//或long
public String execute throws异常{
:
ps.setDate(13,(java.sql.Date)getDateAndTimeOfOccurance());
//或ps.setLong(13,getDateAndTimeOfOccurance());
:
}
解决方案
名称
属性错误。因为你的变量是
private Date dateAndTimeOfOccurance;
您需要在JSP中写:
< sj:datepicker name =dateAndTimeOfOccurance
id =date_time
label =违规的日期和时间
timepicker = $
timepickerAaPm =true
timepickerGridHour =1
timepickerGridMinute =5
timepickerStepMinute =5/>
显然要记住在Action中为该变量生成一个Getter和Setter。
I'm new to struts. I'm using jquery datepicker plugin. I want to get a date(and time) from the user and insert it into the database. When i submit the form, the action class receives 0 value if i set the datatype to long(or int) and it receives null when i set datatype to anything else. I'm not sure what datatype should be used and how it is to be done. Please help
JSP form
<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>
Action class
private Date dateAndTimeOfOccurance;
// or long
public String execute throws Exception{
:
ps.setDate(13, (java.sql.Date) getDateAndTimeOfOccurance());
// or ps.setLong(13, getDateAndTimeOfOccurance());
:
}
解决方案
Your name
attribute is wrong. Since your variable is
private Date dateAndTimeOfOccurance;
you need to write that in JSP:
<sj:datepicker name = "dateAndTimeOfOccurance"
id = "date_time"
label = "Date and Time of Offence"
timepicker = "true"
timepickerAaPm = "true"
timepickerGridHour = "1"
timepickerGridMinute = "5"
timepickerStepMinute = "5"/>
Obviously remember to generate a Getter and a Setter for that variable in the Action.
这篇关于Struts2 jquery datepicker将0或null值传递给action类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文