我想数据库中添加数据的时候只有id添加进了数据库,然后我打印出JSP中获取的值,发现也只能获取到id的数值,代码如下:
JSP:   <tr class="contdcon">
          <td>
         <input name="AssetsTime" type="text" onclick="SelectDate(this,'yyyy-MM-dd')" value="">
         
          </td>
          <td>
             <input name="AssetsSource" type="text" value="">
          </td>
          <td>
              <input name="AssetsCount1" type="float" value="">
          </td>
          <td>
              <input name="AssetsRest1" type="float" value="">
          </td>          
           <td>
             <input name="AssetsUse" type="text" value="">
          </td>
          <td>
             <input name="AssetsBook" type="text" value="">
          </td>                   
        </tr>
      </table>
  </td>
  </tr>
  <tr align="center">
    <td colspan="3" class="contdcon">
     <input name="Button222" type="button" class="botton" value="保存" onClick="return baocun(form)">
    </td>
  </tr>
   <form>
</table>
保存的方法:
public boolean saveAssets(AssetsActionForm form) throws BaseException {

AssetsDh assets = new AssetsDh();

assets.setAssetsTime(form.getAssetsTime());
assets.setAssetsSource(form.getAssetsSource());
assets.setAssetsCount1(form.getAssetsCount1());
assets.setAssetsBook(form.getAssetsBook());
assets.setAssetsRest1(form.getAssetsRest1());
assets.setAssetsUse(form.getAssetsUse());

//主键自动生成 uuid.hex
baseDao.saveObject(assets);

return true;
}
Action:
public ActionForward save( 
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

AssetsActionForm assetsForm = (AssetsActionForm) form;

/*
 * AssetsService这个接口已经实现
 */
AssetsService assetsService = (AssetsService) super.getBean("assetsService");


assetsService.saveAssets(assetsForm);
/*
 * 在这里将JSP页面获取的值打印出来:
 */
System.out.println(assetsForm);

return mapping.findForward("save");
}

解决方案 »

  1.   

    好久没有做过struts了,
    你先检察一下配置, 然后
    察看生成的html代码有没有不妥。
    在action里面用request.getParameter("AssetsSource")看看有没有值。
    <input name="AssetsSource" type="text" value=""> 改成 <input name="AssetsSource" id="AssetsSource" type="text" value=""> .....
      

  2.   

    如果没有异常的话看下这里public boolean saveAssets(AssetsActionForm form) throws BaseException { AssetsDh assets = new AssetsDh(); assets.setAssetsTime(form.getAssetsTime()); 
    assets.setAssetsSource(form.getAssetsSource()); 
    assets.setAssetsCount1(form.getAssetsCount1()); 
    assets.setAssetsBook(form.getAssetsBook()); 
    assets.setAssetsRest1(form.getAssetsRest1()); 
    assets.setAssetsUse(form.getAssetsUse()); 是不是form中的属性都是null
      

  3.   

    你的form有没有提高啊?
    <input name="Button222" type="button" class="botton" value="保存" onClick="return baocun(form)"> 
    onclick事件中有没有提交form?
      

  4.   

    有的,我在javascropt中写了,<SCRIPT type="text/javascript" language="javascript">
    function baocun(form){
    form.action="/JXKH/assets/assets_200Save.do";
    form.submit();
    return true;
    }
    </SCRIPT>
      

  5.   


    你的form名称也叫form吗?
    还有你用动态form吗?有没有在配置文件里配置动态form?
      

  6.   

      我用的是动态Form,配置过了。
      

  7.   

    配置是否如下一致?当然数据类型按你的实际情况
    另外:你在Action的保存方法里将其它代码先注释掉
    输入一行:System.out.println(form);
    看看后台打印出来 form 所有属性是否为空,若为空就说明没有提交
    <form-bean name="form"
    type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="AssetsTime" type="java.util.Date" />
    <form-property name="AssetsSource" type="java.lang.String" />
    <form-property name="AssetsCount1" type="java.lang.String" />
    <form-property name="AssetsRest1" type="java.lang.String" />
    <form-property name="AssetsUse" type="java.lang.String" />
    <form-property name="AssetsBook" type="java.lang.String" />
    </form-bean>
      

  8.   

      打印出来的结果只有id....数据库中也只有id被插进去了~!~!
      

  9.   

    你不是说是动态Form吗?
    动态Form的话不是应该
    form.get("属性名");这样获取属性值吗?还有你的ID不是自动生成的吗?System.out.println(form); 怎么会打印出ID?
      

  10.   

    楼主可以自已调下:
      第一,你自己建个测试类,试下你的baseDao.saveObject()是否好用!
      第二,你打印一下你的from,看看里面有没有值。
      第三,如果以上两个都没有问题,那么也就没有问题了。
      

  11.   

     <input name="AssetsCount1" type="float" value=""> 
    有没有搞错啊,html都不懂就传参数啊,type是html的控件类型,不是数据类型
      

  12.   

    首先楼主对于html控件概念可能有些混淆。
    <input name="AssetsCount1" type="float" value="">
    <input name="AssetsRest1" type="float" value="">
    type是html的控件类型,不是数据类型其次onclick事件中不需要传form的!
    以下前提是当前画面只有一个form表单。
    <SCRIPT type="text/javascript" language="javascript"> 
    function baocun(){ 
     document.forms[0].submit();

    </SCRIPT>
    <html>
    <form name="form1" action="/JXKH/assets/assets_200Save" method="post">
    </form>
    </html>
      

  13.   

    还是不行的,我的控件类型写错了,但是我的javascript是没有错误的,就是那个form..
      

  14.   

    不可能打印出ID来的,你的ID之所以能插进去,是因为你的ID是自动生成,而不是你传过去的。所以说你根本就没把任何值传到后端
      

  15.   

    你的struts-config.xml里assets_200Save.do配置form了没有,比如说
     <action
            name="AssetsActionForm "
            attribute="AssetsActionForm " validate="false" parameter="method" 
            path="/assets_200Save" type="******">
    </action> 
    配置是这样嘛
      

  16.   

    function baocun(form){ 
    form.action="/JXKH/assets/assets_200Save.do"; 
    form.submit(); 
    return true; 

    </SCRIPT>
    这段代码里面="/JXKH/assets/assets_200Save.do"是什么。你的struts在web.xml里还配置路径了?
    你改成
    form.action="<%=request.getContextPath()%>/assets_200Save.do";
    试试看
      

  17.   

    还是不行,控制台打印出com.ninetowns.cs.biz.actionForm.AssetsActionForm@199f755
      

  18.   

    <input name="AssetsCount1" type="float" value=""> 
    改为
    <input name="AssetsCount1" type="text" value="">试试
    顺便我想问一下,你是用的struts中的ActionForm实现的?如果是这样,那这些应该替代为<html:property>标签,这样它才会映射到ActionForm中,如果ActionForm是你自己写的而没有用到struts,那你用request.getparameter(xx)获得input中的值,看看是否有值!如果有值,而Form离没值,可能就是值没有映射到你的form字段中! 
      

  19.   

    无论你是用struts还是你用普通的form,你把你那value属性都给去了!你搞笑呢,,,你动态提交的时候接受传值不影响!
      

  20.   

    设置几个调试点,确认提交参数已经绑定到form中并到Action,然后是下一层。最终到sql
      

  21.   


    同意,SQL语句貌似执行了,但是无参数!
      

  22.   

    楼主,如果你是动态form的话
    在js里提交form是这样的:
    你配置文件里动态form名称.submit();即你的onclick事件调用的方法中要 yourformname.submit();
      

  23.   

    不然怎么可能哩?你说你的是动态 Form
    你看看你最始发的:保存的方法:
    public boolean saveAssets(AssetsActionForm form) throws BaseException {AssetsDh assets = new AssetsDh();assets.setAssetsTime(form.getAssetsTime());
    assets.setAssetsSource(form.getAssetsSource());
    assets.setAssetsCount1(form.getAssetsCount1());
    assets.setAssetsBook(form.getAssetsBook());
    assets.setAssetsRest1(form.getAssetsRest1());
    assets.setAssetsUse(form.getAssetsUse());//主键自动生成 uuid.hex
    baseDao.saveObject(assets);return true;

    动态 form 是这样的吗?
      

  24.   

     我在把Jsp页面发一下:
    <%@ include file="/common-page/taglibs.jsp" %>
    <%@ page contentType="text/html;charset=GBK"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>地下室管理系统</title>
    <link href="<c:url value="/css/css.css"/>" rel="stylesheet" type="text/css">
    <script src="<c:url value="/js/table.js"/>"></script><SCRIPT type="text/javascript" language="javascript">
    function baocun(form){
    form.action="/JXKH/assets/assets_200Save.do";
    form.submit();
    return true;
    }
    </SCRIPT></head><body>
    <div align="center">    
    </div>
    <table width="800" border="0" align="center" cellpadding="3" cellspacing="1" class="contable">
    <form action="/assets/assets_200Save" styleId="frm"  method="post">
      <tr>
        <td colspan="3" class="contable"><strong>新添加软件基金</strong></td>
      </tr>
      <tr>
        <td colspan="3" class="contable">
          <table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="#999999" class="contable">
            <tr class="contdtitle">
              <td>资金汇入时间</td>
              <td>资金来源</td>
              <td>资金总数</td>
          <td>资金余额</td>
              <td>资金用途</td>
              <td>资金使用记录</td>
            </tr> 
      <tr class="contdcon">
              <td>
             <input name="AssetsTime" type="text" onclick="SelectDate(this,'yyyy-MM-dd')" value="">
             
              </td>
              <td>
                  <input name="AssetsSource" id="AssetsSource" type="text" value=""> 
              </td>
              <td>
                  <input name="AssetsCount1" type="text" value="">
              </td>
              <td>
                  <input name="AssetsRest1" type="text" value="">
              </td>          
               <td>
                 <input name="AssetsUse" type="text" value="">
              </td>
              <td>
                 <input name="AssetsBook" type="text" value="">
              </td>                   
            </tr>
          </table>
      </td>
      </tr>
      <tr align="center">
        <td colspan="3" class="contdcon">
         <input name="Button222" type="button" class="botton" value="保存" onClick="return baocun(form)">
        </td>
      </tr>
       <form>
    </table>
    <div align="center">    
    </div>
    </body>
    </html>
    这是struts的配置文件:<form-beans> 
          <form-bean name="userDhActionForm" type="com.ninetowns.cs.biz.actionForm.UserDhActionForm"/>
          <form-bean name="queryDhActionForm" type="com.ninetowns.cs.biz.actionForm.QueryDhActionForm"/>
          <form-bean name="memberDhActionForm" type="com.ninetowns.cs.biz.actionForm.MemberDhActionForm"/>
          <form-bean name="assetsActionForm" type="com.ninetowns.cs.biz.actionForm.AssetsActionForm">
    </form-bean>     </form-beans><action  path="/assets/assets_200List" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request"  parameter="method" >
           <forward name="list" path="/assets/assets_200List.jsp"></forward>
    </action>
    <action path=""></action>
    <action  path="/assets/assets_200View" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request"  parameter="method" >
           <forward name="view" path="/assets/assets_200View.jsp"></forward>
    </action> 
    <action  path="/assets/assets_200Search" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request"  parameter="method" >
           <forward name="search" path="/assets/assets_200Edit.jsp"></forward>
    </action> 
    <action  path="/assets/assets_200Edit" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request" parameter="method" >
           <forward name="edit" path="/assets/assets_200Result.jsp"></forward>
    </action> 
    <action  path="/assets/assets_200Delete" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request" parameter="method" >
           <forward name="delete" path="/assets/assets_200List.do"></forward>
    </action>
    <action path="/assets/assets_200Save" name="assetsActionForm" type="com.ninetowns.cs.web.action.assets.assets_200" scope="request" parameter="method">
    <!-- 和action中的return mapping.findForward("save");中的save要保持一致性,然后进行添加成功后的页面跳转 -->
    <forward name="save" path="/assets/assets_200Result.jsp"></forward>
    </action>
    大家看看,给我的页面改一下我试试,今天结果一出来,我马上结贴...
      

  25.   


    <SCRIPT type="text/javascript" language="javascript">
    function baocun(){
    //form.action="/JXKH/assets/assets_200Save.do";
    assetsActionForm.submit();
    return true;
    }
    </SCRIPT>还有别的不想说你了,看看你的配置文件!!!
    不是用 DispatchAction 吗?
    如果是普通的 Action parameter="method"有什么用?
    <action path="/action" attribute=""
                input="" name="" validate="false"
                scope="request" parameter="method"
                type="yourActionClass">
            </action>.../action?method=yourActionMethod