function setDefaultDate()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
oDate1 = document.forms[0].elements["item.svrCreateDate"];
if (oDate1.value=="")
{
oDate1.value = year+"-"+month+"-"+(day-1);
}
oDate2 = document.forms[0].elements["item.svrCreateDate2"];
if (oDate2.value=="")
{
oDate2.value = (year+1)+"-"+month+"-"+day;
}
}补充一下 初始化会调用这个

解决方案 »

  1.   

    Struts2吗?
    为什么不直接用时间标签?
      

  2.   

    在将formbean转化成pojo出错,formbean中的属性是String,而pojo中为date,像这种作为查询条件但是数据库中没有的字段,最好不要放在pojo的属性
      

  3.   

    有3个疑问
    1.
    private Date svrCreateDate2
    这个是查询用的?但是在映射文件里并没有啊2.从前台怎么传Date型数据过来,不是只能是String或者boolean吗?3.你把什么改成String型了?
      

  4.   

    关键是在映射文件里并没有svrCreateDate2啊
      

  5.   


    正确,
    jsp中的表单传送的都是string,你可以写个data类在后台转换,
    转个别人写的类,
    public class DateUtility {

    public DateUtility() {
    }

    static public String format(java.util.Date date,String pattern) {
    SimpleDateFormat df = new SimpleDateFormat(pattern,Locale.UK);
    return df.format(date);
    }

    static public Date getDate(String str) {
    SimpleDateFormat df = null;
    if(str.length()==10) {
    df = new SimpleDateFormat("yyyy-MM-dd",Locale.UK);
    }
    else if(str.length()==16) {
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm",Locale.UK);
    }
    else if(str.length()==19) {
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.UK);
    }
    else {
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",Locale.UK);
    }
    Date date = df.parse(str,new ParsePosition(0));
    //if(date==null) date = new java.util.Date();
    return date;
    }

    static public Date getDate(String str,String pattern) {
    SimpleDateFormat df = new SimpleDateFormat(pattern,Locale.UK);
    Date date = df.parse(str,new ParsePosition(0));
    return date;
    }

    static public String toTimestampFormat(String str) {
    return new Timestamp(getDate(str).getTime()).toString();
    }

    public static Timestamp getTimestamp(String str) {
    if(str==null) return null;
    else return new Timestamp(getDate(str).getTime());
    }

    public static Timestamp getTimestamp(String str,String pattern) {
    if(str==null) return null;
    else return new Timestamp(getDate(str,pattern).getTime());
    } public static Timestamp getTimestamp(java.util.Date date) {
    if(date==null) return null;
    else return new Timestamp(date.getTime());
    }

    public static java.sql.Date getSqlDate(java.util.Date date) {
    if(date==null) return null;
    else return new java.sql.Date(date.getTime());
    }

    public static java.sql.Date getSqlDate(String str) {
    if(str==null) return null;
    else return new java.sql.Date(getDate(str).getTime());
    }

    public static java.sql.Date getSqlDate(String str,String pattern) {
    if(str==null) return null;
    else return new java.sql.Date(getDate(str,pattern).getTime());
    }
    }
      

  6.   

    简单的搜索可以用pojo做条件,但是有时搜条件比较多,并且这些条件都不是pojo的属性
    ,这时我一般建一个search的包,里面放各种搜索对象,然后用request的各个属性去初始化这个对象的值,
    在action中再根据这个对象去构造hql
      

  7.   


    private Date svrCreateDate2;// 用作查询条件 建议把这个类型改为String类型试试你的调用方法的参数类型是否一致?
    你检查一下
      

  8.   

    10楼的 struts1.x 的actionForm不支持date类型哈
      

  9.   

    呵呵,第一个就是你们都认同的,可能是类型之间的错误.可能是string啊,date啊,什么的,出现问题.第二:就是楼主的jsp里面用两行来分开,显示不知道有没有问题.,设置断点查一下吧,如果它能够执行到你所需要的那一步的话.
      

  10.   

    肯定是构造pojo时出了问题,form中的svrCreateDate是String,pojo中svrCreateDate是Date,apache在转换的时候会直接用String的值去设置pojo,肯定报错
      

  11.   

    除了7楼所说的 转换
    有什么解决方法吗?
    页面中就可以传递String boolean?
      

  12.   

    你直接在配置文件里面配置java.util.Date
    String转化为Date就会出现异常,就好是写个自定义的转换器,再注入,
    就行了,我遇到过,要写的转换器我这里有,要的话,加我QQ:253792300
      

  13.   

    对的,要自己写一个String和Date类型转换的自定义类型。
      

  14.   

    LZ用到了自定义类型了,需要把原始DATE类型转换成分YY MM DD 的字符串形式自己写个转换类,在STRUTS中配置一下记得把POJO类累的DATE属性改为String;
      

  15.   

    不是简单的simpleDateFormat("yyyy-MM-dd")
    是spring的Date转换器,写好了还要注入的
    不然,都不认识的!
      

  16.   


    <%@ page language="java" pageEncoding="GBK" import="com.yy.pojo.SysUser" %>
    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
    <%@ taglib uri="/WEB-INF/jb-common.tld" prefix="jb"%>
    <script src="validate.js"></script>
    <script src="icommon.js"></script><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html lang="true">
    <head>
    <title>客户服务管理</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <script>
    function doDel(id){
    if ( window.confirm("确定删除?") ){
    window.location.href = "?o=doDel&id=" + id;
    }
    }
    function setDefaultDate()
    {
    var now=new Date();
    var year=now.getYear();
    var month=now.getMonth();
    var day=now.getDate();
    var hours=now.getHours();
    var minutes=now.getMinutes();
    var seconds=now.getSeconds();
    oDate1 = document.forms[0].elements["item.temp"];
    if (oDate1.value=="")
    {
    oDate1.value = year+"-"+month+"-"+(day-1);
    }
    oDate2 = document.forms[0].elements["item.svrCreateDate2"];
    if (oDate2.value=="")
    {
    oDate2.value = (year+1)+"-"+month+"-"+day;
    }
    }
    function doSearch()
    {
    setDefaultDate();
    doSubmit('${param.o }');
    }
    function setLabel(oSrc,tTargetLabelName,tTargetIdName)
    {
    var oLabelCtl = document.forms[0].elements[tTargetLabelName];
    var oIdCtl = document.forms[0].elements[tTargetIdName];
    oLabelCtl.value = oSrc.options[oSrc.selectedIndex].text;
    oIdCtl.value = oSrc.options[oSrc.selectedIndex].value;
    }
    function doDispatch(svrId)
    {

    if (!document.forms[0].elements["svrDueId"].value)
    {
    alert("请选择分配给的人员");
    return ;
    }
    alert(svrId);
    setDefaultDate();
    document.forms[0].elements['svrId'].value = svrId;
    doSubmit('doDispatch');
    }
    </script>
    </head>
    <body>
    <html:form action="service">
    <html:hidden property="o" value="toList" />
    <input type="hidden" name="svrId" />
    <input type="hidden" name="svrDueId" />
    <input type="hidden" name="svrDueTo" />
    <div class="page_title">客户服务管理</div>
    <div class="button_bar">
    <button class="common_button" onclick="help('');">帮助</button>
    <button class="common_button"
    onclick="window.location.href='?o=toAdd';">新建</button>
    <button class="common_button" onclick="javascript:doSearch();">查询</button>
    </div>
    <table class="query_form_table" border="0" cellPadding="3"
    cellSpacing="0">
    <tr>
    <th>服务类型</th>
    <td><html:text property="item.svrType" /></td>
    <th>概要</th>
    <td><html:text property="item.svrTitle" /></td>
    </tr>
    <tr>
    <th>客户</th>
    <td><html:text property="item.svrCustName" /></td>
    <th>创建时间<br />(日期格式:2008-02-22)</th>
    <td><html:text property="item.temp" size="10" />-<html:text property="item.svrCreateDate2" size="10" /></td>
    </tr>
    </table>
    <!-- 列表数据 -->
    <br />
    <table class="data_list_table" border="0" cellPadding="3"
    cellSpacing="0">
    <tr>
    <th onclick="order_by('svrId');">编号</th>
    <th onclick="order_by('svrType');">服务类型</th>
    <th onclick="order_by('svrTitle');">概要</th>
    <th onclick="order_by('svrCustName');">客户</th>
    <th onclick="order_by('svrCreateBy');">创建人</th>
    <th onclick="order_by('svrCreateDate');">创建时间</th>
    <th onclick="order_by('svrDueTo');">分配给</th>
    <th>操作</th>
    </tr>
    <logic:iterate id="item" name="serviceForm" property="pageResult.list"
    type="com.yy.pojo.CstService">
    <tr>
    <td class="list_data_number">${item.svrId }&nbsp;</td>
    <td class="list_data_text">${item.svrType }&nbsp;</td>
    <td class="list_data_ltext">${item.svrTitle }&nbsp;</td> <td class="list_data_text">${item.svrCustName }&nbsp;</td> <td class="list_data_text">${item.svrCreateBy }&nbsp;</td>
    <td class="list_data_text"><bean:write name="item"
    property="svrCreateDate" format="yyyy年MM月dd日" />&nbsp;</td> <td class="list_data_text">
    <!--  <select property="xx" onchange="setLabel(this,'svrDueTo','svrDueId');">
    <option value="0">未指定</option>
    userOptions%>
    </select> -->
    <html:select property="item.svrType" onchange="setLabel(this,'svrDueTo','svrDueId');">
    <html:option value="">未指定</html:option>
    <html:optionsCollection name="USERS_OPTIONS" label="usrName" value="usrId"/>
    </html:select>
    <button onclick="doDispatch('${item.svrId }');">分配</button>
    </td>
    <td class="list_data_op"><img
    onclick="doDel('${item.svrId }');" title="删除"
    src="images/bt_del.gif" class="op_button" /></td>
    </tr>
    </logic:iterate>
    <logic:empty name="serviceForm" property="pageResult.list">
    <tr>
    <td class="data_cell" colspan="20"
    style="text-align:center;height:40px;">没有记录</td>
    </tr>
    </logic:empty>
    <tr>
    <td colspan="20" style="padding:0 1px;">
    <div class="pager"><jb:pager form="serviceForm" /></div>
    </td>
    </tr>
    </table></html:form>
    </body>
    </html:html>这是我页面所写的 
      

  17.   

       struts和spring都需要配置属性编辑器,才能处理特殊类型的~~~~~~~~~
      

  18.   


    <bean
    class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    <property name="customEditors">
    <map>
    <entry key="com.baobaotao.editor.Car">
    <bean class="com.baobaotao.editor.CustomCarEditor" />
    </entry>
    </map>
    </property>
    </bean>