(笔记)关于刷新添加数据的Bug存在的原因

1)many to one 关系表中cacsade属性,将属性设置为“add-update persist”可以在有级联关系的表中强制增加数据;

2)在呈现预览功能时最好是action 或者页面直接传值。建立一个简单的Viewbean也能解决此问题,但是的注意如果是同过get set方法取值的时候,数据会自动的set到取值的页面,影响下一步的操作;

3)代码:

public String add(){
//去掉这句执行语句红色部分?是否可以直接在此处进行对象的添加
[color=red]String sName=this.getBranchdirectory();
this.ebaySortinfo= this.sortinfoDao.getSortsBySname(sName);

this.ebayBuygoods.setEbaySortinfo(ebaySortinfo);[/color]
// EbayUserinfo user=(EbayUserinfo)session.get();
// this.ebayBuygoods.setEbayUserinfo(user);
this.user=this.userinfoDao.getUserById("306");
System.out.println(this.user.getUName());
this.ebayBuygoods.setEbayUserinfo(user);

this.buygoodsDao.addBuyinglead(this.ebayBuygoods);
System.out.println(this.ebayBuygoods.getBContent());
System.out.println(this.ebayBuygoods.getBName());
return "add";
}


public String previous(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String s_date=String.valueOf(sdf.format(new Date()));

String Sname=this.getBranchdirectory();
this.ebaySortinfo= this.sortinfoDao.getSortsBySname(Sname);
// System.out.println(this.ebaySortinfo.getSId());
// System.out.println(this.ebayBuygoods.getBContent());
this.ebayBuygoods.setEbaySortinfo(ebaySortinfo);

this.user=this.userinfoDao.getUserById("306");
this.ebayBuygoods.setEbayUserinfo(user);

// System.out.println(Sname);
this.ebayBuygoods.setCreatetime(s_date);
this.ebayBuygoods.setBEndtime(Nextmonth.getNextMonth(s_date));
this.ebayBuygoods.setBAble("1");

this.setEbayBuygoods(this.ebayBuygoods);
return "previous";
}


去掉红色的代码,先执行预览,然后执行添加,数据还会添加到数据库中,值得一提的是红色部分的数据会一直保存在该页面上...

页面的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的 Ebay——商品发布</title>
</head>
<link rel="stylesheet" type="text/css" href="styles.css">
<script language="JavaScript" type="text/javascript">
var branchdirectory=[
["电脑","MP3","MP4","相机"],
["经济","文学","证劵","小说"],
["防晒霜","洗面奶","沐浴露","洗发水"],
["男装","女装","童装","内衣"],
["皮鞋","波鞋","沙滩鞋","布鞋"]
];


//alert(branchdirectory.length);
function getBranchdirectory(){
var sltMaindirectory=document.forms["loginfrm"].elements["Maindirectory"];
//alert(sltMaindirectory.length);
var sltBranchdirectory=document.forms["loginfrm"].elements["Branchdirectory"];
//alert(sltMaindirectory.selectedIndex);
var maindirectory=branchdirectory[sltMaindirectory.selectedIndex-1];
sltBranchdirectory.length=1;

for (var i=0;i<maindirectory.length; i++ )
{sltBranchdirectory[i+1]=new Option(maindirectory[i],maindirectory[i]);

}
}

function previous(){
var branchdirectory=document.getElementById("Branchdirectory").value;

location.href="previousMyGood.action?branchdirectory="+branchdirectory;
}


</script>

<body>
<!--<form method="post" action="addBuygoods.action" name="loginfrm"> -->

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="800" rowspan="2"><img src="image/logo.gif" width="170" height="44" /></td>
<td width="630" align="right"><a
href="#"> 买东西 </a>|<a
href="#"> 卖东西 </a>|<a
href="#"> 我的Ebay</a> |<a
href="#"> 逛商店</a></td>
</tr>
<tr >
<td align="right">您好  <span class="STYLE4 STYLE2">☺</span>   Daniel    退出 
 </td>
</tr>
<br>
<table width="960" border="0" height="40px" cellspacing="0" cellpadding="0" align="center" background="image/logon_02.gif" >
<tr>
<td width="253" > </td>
<td width="222" > <select name="">
<option value="出售信息">出售信息</option>
<option value="求购信息">求购信息</option>

</select>
  
<input name="textfield" type="text" size="20" class="text"/></td>
<td width="288" >   
<input type="submit" name="Submit" value="搜 索" class="btn"/>
   </td>
<td width="197" > </td>
</tr>
</table>
<br>


<tr>
<td width="148"><TABLE width="800" border=0 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD width="160" vAlign=top id=leftCol>
<TABLE width="148" cellPadding=0 cellSpacing=0 class=helpnav>
<TR>
<TD width="148" height="26px" background="image/bg_01.gif" >
<font color="#FFFFFF" size="2">     我是买家</font>
</TD>
</TR>
<TR>
<TD class=category>
<UL>
<LI ><A
href="myBoughtGoodList.action">我购买的商品</A>
<LI ><A
href="listBuyGoods.action">我的求购信息</A>
<LI ><A
href="buyinglead.jsp">发布求购信息</A>
</UL>
</td></tr>
<TR>
<TD height="26px" background="image/bg_01.gif">
<font color="#FFFFFF" size="2">     我是卖家</font>
</TD></TR>
<TR>
<TD class=category>
<UL>
<LI >
<A href="SaledPro.html">已经卖出的商品</A>
<LI >
<A href="AuctionPro.html">出售中的商品</A>
<LI >
<A href="StoreHousePro.html">仓库里的商品</A>
<LI
><A style="COLOR: #ff6600" href="SalingPro.html">商品发布</A>
</UL>
</td></tr>
<TR>
<TD height="26px" background="image/logon01.gif">
<font color="#FFFFFF" size="2">     个人设定</font>
</TD></TR>
<TR>
<TD class=category>
<UL>
<LI ><A
href="">个人信息修改</A>

</TD>
</TR>
</TABLE></td>
<td width="661" valign="top"><table width="640" border="0" height="28" cellspacing="0" cellpadding="0" align="right">
<tr>
</tr>
<tr>
<td colspan="2"><table width="640" border="0" cellspacing="0" cellpadding="0">
<tr>

<td>
<s:form method="post" action="buygoods.action" name="loginfrm" target="_blank">

<table width="640" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td colspan="2" background="image/table_02.gif" height="28">  <strong>商品发布</strong></td>
</tr>
<tr>
<td width="158" align="right">商品名称  </td>
<td width="476">   <input name="ebayBuygoods.BName" type="text" size="28" maxlength="30" class="text"/></td>
</tr>
<tr>
<td align="right">商品种类  </td>
<td>   <select name="Maindirectory" οnchange="getBranchdirectory()">
<option value="" >--请选择一个分类--</option>
<option value="264">数码</option>
<option value="Reading Material">阅读书籍</option>
<option value="Cosmetic">化妆品</option>
<option value="263">服装</option>
<option value="Shoses">鞋类</option>
</select>
<select name="Branchdirectory">
<option value="0"> --请选择--</option>
</select>
</td>
</tr>
<tr>
<td align="right">商品价格  </td>
<td>   <input name="ebayBuygoods.BPrice" type="text" size="28" maxlength="30" class="text"/></td>
</tr>
<tr>
<td align="right">数量  </td>
<td>   <input name="ebayBuygoods.BQuantity" type="text" size="28" maxlength="30" class="text"/></td>
</tr>
<tr>
<td align="right">商品描述  </td>
<td>   <textarea name="ebayBuygoods.BContent" cols="10" rows="4" class="text"></textarea></td>
</tr>

</table>
<!-- <table width="640" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提 交" />  <input name="name2" type="button" value="预 览" οnclick="javascript:previous();"/>  <a href="#"><input type="button" value="返 回" /></a></td>
</tr>
</table> -->

<table width="640" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center"><s:submit value="提 交" method="add"/>  <s:submit value="预 览" method="previous"/>  </td><td><input type="reset" value="重设"/></td>
</tr>
</table>
</s:form>
</td>
</tr>
</table>
</td>
</tr>


</table>
</td>
</tr>
</table>


<br/>
<hr align="center" width="800" />
<center> Copyright ©武汉大工尹科技发展有限公司. All Rights Reserved </center>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值