日期:2014-05-17  浏览次数:20851 次

页面刷新一就行增一条记录的问题
说明:我查询车辆申请信息,将申请信息显示在页面每刷新一次,页面上就多一条记录,数据库里面也会相应的多一条记录

1.doPost:
Java code


    String cNumber = request.getParameter("cnumber");
        String cID = request.getParameter("cid");
        int id = Integer.parseInt(cID);
        String aName = request.getParameter("name");
        String aDepart = request.getParameter("dept");
        String aReason = request.getParameter("reason");
        String aTime = request.getParameter("date");
        String status = "1";
        String path = null;
        List<Record> list=null;
        boolean uFlag,iFlag;
        try
        {
                           //此方法为申请车辆的方法,一申请就改变车辆的当前状态
            uFlag = CarsFactory.getCarsDAOInstances().UpdateStatus(id, status);
//此方法将申请记录插入到数据库            
iFlag=CarsFactory.getRecordDAOInstances().doInsertResord(cNumber, aName, aDepart, aReason, aTime);
//此方法获取车牌号码对应的申请记录
            list=CarsFactory.getRecordDAOInstances().querryByRid(cNumber);
            
            if (uFlag&iFlag)
            {
                //申请成功将申请的信息发送给浏览器
                request.setAttribute("redList", list);
                path = "cars/querryapp.jsp";
            } else
            {
                path = "errors/Error.jsp";
            }
            request.getRequestDispatcher(path).forward(request, response);
        } catch (Exception e)
        {
            System.out.print(e);
        }



2.页面
HTML code

<jason:forEach items="${redList}" var="record">
                        <tr>
                            <td height="25" align="center">
                            ${record.rid}
                            </td>
                            <td align="center">
                                ${record.cno}
                            </td>
                            <td align="center">
                                ${record.owner }
                            </td>
                            <td align="center">
                                ${record.departName }
                            </td>
                            <td align="center">
                                ${record.reason }
                            </td>
                            <td align="center">
                                ${record.date }
                            </td>
                        </tr>
                    </jason:forEach>



------解决方案--------------------
Java code

//此方法将申请记录插入到数据库            
iFlag=CarsFactory.getRecordDAOInstances().doInsertResord(cNumber, aName, aDepart, aReason, aTime);

------解决方案--------------------
每次刷新页面,就会向服务器发送一次请求,就会执行一次dopost方法,就会执行一次插入操作。。。so。