首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-11-14 
(笔记)关于刷新添加数据的Bug存在的原因1)many to one 关系表中cacsade属性,将属性设置为“add-update pers

(笔记)关于刷新添加数据的Bug存在的原因
1)many to one 关系表中cacsade属性,将属性设置为“add-update persist”可以在有级联关系的表中强制增加数据;

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

3)代码:

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

this.ebayBuygoods.setEbaySortinfo(ebaySortinfo);
//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">您好&nbsp;&nbsp;<span border="0" height="40px" cellspacing="0" cellpadding="0" align="center" background="image/logon_02.gif"  >
  <tr>
    <td width="253" >&nbsp;</td>
<td width="222" >&nbsp;<select name="">
  <option value="出售信息">出售信息</option>
  <option value="求购信息">求购信息</option>
 
</select>
&nbsp;&nbsp;
    <input name="textfield" type="text" size="20"  >&nbsp;&nbsp;&nbsp;
    <input type="submit" name="Submit" value="搜 索"  >&nbsp;</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"> &nbsp;&nbsp;&nbsp;&nbsp;我是买家</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"> &nbsp;&nbsp;&nbsp;&nbsp;我是卖家</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"> &nbsp;&nbsp;&nbsp;&nbsp;个人设定</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">&nbsp;&nbsp;<strong>商品发布</strong></td>
    </tr>
  <tr>
    <td width="158" align="right">商品名称&nbsp;&nbsp;</td>
    <td width="476">&nbsp;&nbsp;&nbsp;<input name="ebayBuygoods.BName" type="text" size="28" maxlength="30" onchange="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">商品价格&nbsp;&nbsp;</td>
    <td>&nbsp;&nbsp;&nbsp;<input name="ebayBuygoods.BPrice" type="text" size="28" maxlength="30" type="text" size="28" maxlength="30" cols="10" rows="4" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" value="提 交" />&nbsp;&nbsp;<input name="name2" type="button" value="预 览"  onclick="javascript:previous();"/>&nbsp;&nbsp;<a href="#"><input type="button" value="返 回" /></a></td>
    </tr>
</table>  -->

<table width="640" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="center"><s:submit value="提 交" method="add"/>&nbsp;&nbsp;<s:submit value="预 览" method="previous"/>&nbsp;&nbsp;</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 &copy;武汉大工尹科技发展有限公司. All Rights Reserved </center>
</body>
</html>

热点排行