当前位置: 代码迷 >> J2EE >> 交付form表单action代码执行两次?是struts2
  详细解决方案

交付form表单action代码执行两次?是struts2

热度:104   发布时间:2016-04-22 00:22:52.0
提交form表单action代码执行两次?!!!!!!!是struts2
问题很奇怪,测了下是在最后的form表单(句号那),只要迭代从后台传来的list的值就会让action代码执行两次

HTML code
<%@ page language="java" import="com.sykjw.entity.*,java.util.*,com.sykjw.vo.BasketFee" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <base href="<%=basePath%>">  <title> New Document </title>      <meta http-equiv="pragma" content="no-cache" charset=UTF-8">     <meta http-equiv="cache-control" content="no-cache">    <meta http-equiv="expires" content="0">        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">     <script type="text/javascript">        function dinggou(id,type){        var a = "#goods"+id ;        var type = type ;        var amount ;        var url ;        if(type == "1"){    //点击订购button触发                    alert(type) ;            amount = $("#goods"+id).attr("value");            url = 'json/addGoods.action' ;                    }                    var req = {                "id":id,                "amount":amount,        };                 //var params = Form.serialize('form1');        //创建Ajax.Request对象,对应于发送请求        $.post(url,req,function processResponse(date){                alert("回调函数1") ;        var  string = "<h3 id='goback' style='cursor:pointer'>我的购物车</h3>"             +" <font style='color:blue'>提醒:根据你最终提交订单时间,订餐时间可能有所调整</font>"             + "<table width='100%' border='1' style='border:1px solid #FFB31D' height='auto' cellpadding='0' cellspacing='0'>"             + " <tr ><th scope='col' style='border-bottom:1px solid #FFB31D'>品名</th>"             + "<th scope='col' style='border-bottom:1px solid #FFB31D'>数量(份)</th>"             + "<th scope='col' style='border-bottom:1px solid #FFB31D'>价格(元)</th>"             + "<th scope='col' style='border-bottom:1px solid #FFB31D'>取消</th></tr>";             alert("回调函数2") ;        for(var name in date.cart){            string += "<tr><td style='border-bottom:1px solid #FFB31D;' width='35%'>"+date.cart[name].name+"</td>"                            +"<td style='border-bottom:1px solid #FFB31D'><img src='images/logo/btn_minus.gif' alt=''></img>&nbsp;&nbsp;"                            +"<input type='text' size='2' value="+date.cart[name].amount+" />&nbsp;&nbsp;<img src='images/logo/btn_add.gif' alt=''></img></td>"                           +"<td style='border-bottom:1px solid #FFB31D;' width='35%'>" +date.cart[name].subTotal+"</td>"                           + "<td style='border-bottom:1px solid #FFB31D' width='15%'><img src='images/logo/btn_close.gif' alt='取消'></img></td></tr>";            //alert(name + " and count is =" + date.cart[name].amount);//不确定的属性使用in表达式        }        alert("回调函数3") ;        string += "</table>";         string += "<div style='position:relative;top:40px;width:99.5%;height:70px;'>"                       +"<table width='100%' border='0' height='auto' cellpadding='0' cellspacing='0'> "                       + "<tr> <td  style='border-bottom:1px solid #FFB31D;border-top:1px solid #FFB31D'>小计:</td>"                       + "<td  style='border-bottom:1px solid #FFB31D;;border-top:1px solid #FFB31D'>"+date.basketFee.total-date.basketFee.fee+"</td></tr>"                       + "<tr><td  style='border-bottom:1px solid #FFB31D'>外送费:</td><td  style='border-bottom:1px solid #FFB31D'>"+date.basketFee.fee+"</td></tr>"                       + "<tr><td  style='border-bottom:1px solid #FFB31D'>合计:</td><td  style='border-bottom:1px solid #FFB31D'>"+date.basketFee.total+"</td></tr>"                        + "</table>";        alert("回调函数4") ;        $("#gwc_content").html(string);         //重写购物车的table        alert("ok la") ;        },'json')    };    </script>    <script type="text/javascript">                           $(".left_nav_list li").each(function(index){                $(this).click(function(){                    $(".show").removeClass("show");                    $(".menu").eq(index).addClass("show");                });            });            $("#gouwuche").click(function(){                            $("#gwc_content").toggle(500);            });            $("#goback").click(function(){                $("#gwc_content").toggle(500);})       })    </script>    <style type="text/css">     body     {margin:0px;        padding:0px;     }     #container     {        position:relative;        width:595px;        height:580px;        overflow:auto;     }     #container .list     {        width:150px;        height:250px;        border:1px solid black;        float:left;        margin-left:6%;        margin-top:5px;     }     img     {        cursor:pointer;     }    </style> </head>  <%       Map<Integer,BasketVO> cart = (Map<Integer,BasketVO>)session.getAttribute("cart") ;    BasketFee basketFee = (BasketFee)session.getAttribute("basketFee") ;        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd") ;              String today = simpleDateFormat.format(new Date()) ;                           Date date=null;            date = new SimpleDateFormat("yy-MM-dd").parse(today);                            Calendar c = Calendar.getInstance();            c.setTime(date);            int day=c.get(Calendar.DATE);            c.set(Calendar.DATE,day+1);               String tomorrow = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());            List<String> avalidTimeList = (List<String>)request.getAttribute("avalidTimeList") ;            String s1 = avalidTimeList.get(0) ;  %> <body>    <div id="container">        <s:iterator value="goodsList" var="goods">                <div class="list">                    <img src=${image} width="99.9%" alt=""></img>                    <div style="width:99.6%;height:20px;text-align:center;line-height:20px;">                        <font style="font-size:13px;font-weight:bold;color:red">${name}</font>                    </div>                    <div style="width:99.6%;height:30px;line-height:30px">                        <s:if test="isSale == 1"><font style="font-size:13px;font-weight:bold;color:red">&nbsp;&nbsp;${promotionPrice }/份</font></s:if>                        <s:else><font style="font-size:13px;font-weight:bold;color:red">&nbsp;&nbsp;${salePrice }/份</font></s:else>                        <input type="text" name="amount" id="goods${id}" value="1"  onkeyup="this.value=this.value.replace(/\D/g,'')"  maxlength="2" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:30px;height:13px" /><font style="font-size:13px;font-weight:bold;color:red">份</font>                    </div>                    <br />                    <div style="width:99.6%;height:30px;line-height:30px;text-align:center">                        <img id="img" src="images/logo/order_button.png" alt="" onclick="dinggou(${id},1)"></img>                    </div>                </div>            </s:iterator>                </div>    <div id="gouwuche">        &nbsp;&nbsp;<img src="images/logo/cale.png" alt=""></img><font style="font-size:10pt">购物车</font>    </div>    <div id="gwc_content">            <h4 id="goback" style="cursor:pointer">购物车(点我收起)</h4>            <font style="color:blue">提醒:根据你最终提交订单时间,订餐时间可能有所调整</font>                        <div id="g" style="overflow:auto;width:100%;height:130px">                <table width="100%" border="0" style="border:1px solid #FFB31D" height="auto" cellpadding="0" cellspacing="0">                  <tr >                    <th scope="col" style="border-bottom:1px solid #FFB31D">品名<br><br></th>                    <th scope="col" style="border-bottom:1px solid #FFB31D">数量(份)<br><br></th>                    <th scope="col" style="border-bottom:1px solid #FFB31D">价格(元)<br><br></th>                    <th scope="col" style="border-bottom:1px solid #FFB31D">取消<br><br></th>                  </tr>                  <%                    if(cart != null){                          for (Object o : cart.keySet()) {                  %>                  <tr>                    <td style="border-bottom:1px solid #FFB31D;" width="33%"align="center" valign="middle"><%=cart.get(o).getName() %></td>                    <td style="border-bottom:1px solid #FFB31D" width="35%"align="center" valign="middle"><img src="images/logo/btn_minus.gif" alt="" onclick="dinggou(<%=cart.get(o).getId() %>,2)"></img>&nbsp;<input id="gwc_amount" type="text"  maxlength="2" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" onBlur="dinggou(<%=cart.get(o).getId() %>,4)" size="2" value=<%=cart.get(o).getAmount() %> />&nbsp;<img src="images/logo/btn_add.gif" alt="" onclick="dinggou(<%=cart.get(o).getId() %>,3)"></img></td>                    <td style="border-bottom:1px solid #FFB31D" width="20%"align="center" valign="middle"><%=cart.get(o).getSubtotal() %></td>                    <td style="border-bottom:1px solid #FFB31D" width="12%" align="center" valign="middle"><img src="images/logo/btn_close.gif" alt="取消" onclick="dinggou(<%=cart.get(o).getId() %>,5)"></img></td>                  </tr>                  <%                          }                    }                  %>                 </table>            </div>            <div style="position:absolute;bottom:43px;width:99.5%;height:70px;">                <table width="100%" border="0" height="70px" cellpadding="0" cellspacing="0">                <tr>                    <td align="center"width="45%" style="color:red;border-bottom:1px solid #FFB31D;border-top:1px solid #FFB31D">小计(RMB):</td>                    <td  align="center" width="55%"style="color:red;border-bottom:1px solid #FFB31D;;border-top:1px solid #FFB31D"></td>                </tr>                <tr>                    <td align="center" style="color:red;border-bottom:1px solid #FFB31D">外送费(RMB):</td>                    <td align="center" style="color:red;border-bottom:1px solid #FFB31D"></td>                </tr>                <tr>                    <td align="center" style="color:red;border-bottom:1px solid #FFB31D">合计(RMB):</td>                    <td align="center" style="color:red;border-bottom:1px solid #FFB31D"></td>                </tr>                                </table>            </div>            <div style="position:absolute;bottom:-25px;width:99.5%;height:70px;">                <form action="addOrder" method="post">                    <select name="dealDate" style="width:150px;" >                        <s:iterator value="avalidTimeList">                            <option>。。。</option>                        </s:iterator>                    </select>                    &nbsp;&nbsp;<input type="button" value="全部清空" onclick="dinggou(0,6)"/>&nbsp;&nbsp;                    <input type="submit" value="下订单"></input>                </form>            </div>    </div> </body></html>
  相关解决方案