Struts2 jquery datepicker将0或null值传递给action类 [英] Struts2 jquery datepicker passing 0 or null value to action class

查看:155
本文介绍了Struts2 jquery datepicker将0或null值传递给action类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的struts。我正在使用jquery datepicker插件。我想从用户那里获取日期(和时间)并将其插入到数据库中。当我提交表单时,如果我将数据类型设置为long(或int),则操作类接收0值,并且当我将数据类型设置为其他任何东西时,它接收到null。我不知道应该使用什么数据类型以及如何完成。请帮助



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆