我想数据库中添加数据的时候只有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");
}
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");
}
解决方案 »
- gnu.io.RXTXCommDriver使用中出现错误,请帮忙解决
- 文字替换问题
- 请教js 赋值 带|| 的问题
- 请问哪可以租借到jsp空间
- 请高人指点,关于tomcat5.0.28连接oracle9i的问题
- 求flex流程设计器 如何集成到现有J2EE项目中
- 测试
- 由a.jsp提交到b.jsp,在b.jsp末尾使用<jsp:forward page="c.jsp">。。。。
- 疑难问题,fileupload如何接收同名checkbox的值
- 请教各位:一些网站上介绍DBConnectionManager servlet连接池的具体实现方法.
- javascript的问题。。。。。
- jsp指令标签就2个吗?jsp动作都有什么(全部)
你先检察一下配置, 然后
察看生成的html代码有没有不妥。
在action里面用request.getParameter("AssetsSource")看看有没有值。
<input name="AssetsSource" type="text" value=""> 改成 <input name="AssetsSource" id="AssetsSource" type="text" value=""> .....
assets.setAssetsSource(form.getAssetsSource());
assets.setAssetsCount1(form.getAssetsCount1());
assets.setAssetsBook(form.getAssetsBook());
assets.setAssetsRest1(form.getAssetsRest1());
assets.setAssetsUse(form.getAssetsUse()); 是不是form中的属性都是null
<input name="Button222" type="button" class="botton" value="保存" onClick="return baocun(form)">
onclick事件中有没有提交form?
function baocun(form){
form.action="/JXKH/assets/assets_200Save.do";
form.submit();
return true;
}
</SCRIPT>
你的form名称也叫form吗?
还有你用动态form吗?有没有在配置文件里配置动态form?
另外:你在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>
动态Form的话不是应该
form.get("属性名");这样获取属性值吗?还有你的ID不是自动生成的吗?System.out.println(form); 怎么会打印出ID?
第一,你自己建个测试类,试下你的baseDao.saveObject()是否好用!
第二,你打印一下你的from,看看里面有没有值。
第三,如果以上两个都没有问题,那么也就没有问题了。
有没有搞错啊,html都不懂就传参数啊,type是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>
<action
name="AssetsActionForm "
attribute="AssetsActionForm " validate="false" parameter="method"
path="/assets_200Save" type="******">
</action>
配置是这样嘛
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";
试试看
改为
<input name="AssetsCount1" type="text" value="">试试
顺便我想问一下,你是用的struts中的ActionForm实现的?如果是这样,那这些应该替代为<html:property>标签,这样它才会映射到ActionForm中,如果ActionForm是你自己写的而没有用到struts,那你用request.getparameter(xx)获得input中的值,看看是否有值!如果有值,而Form离没值,可能就是值没有映射到你的form字段中!
同意,SQL语句貌似执行了,但是无参数!
在js里提交form是这样的:
你配置文件里动态form名称.submit();即你的onclick事件调用的方法中要 yourformname.submit();
你看看你最始发的:保存的方法:
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 是这样的吗?
<%@ 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>
大家看看,给我的页面改一下我试试,今天结果一出来,我马上结贴...
<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