Heim > Artikel > Web-Frontend > web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose
这是一个订单展示然后有一个按钮取消订单的
这个链接按钮应该是放在form里
但是因为我的订单是从数据库里调的
不知道有多少个订单
所以form也应该是动态生成的
像我这样写可以 只用了一个form 一个订单
要是把form放到循环里就没用了
就是下面这样
ReserveList里面已经存好了多个订单对象
for(int i=0;i< ReserveList.size();i++) {out.println("<form name='form7'action='/g0103/servlet/servBDReserveCancel?rnum="+ReserveList.get(0).getReserveNum()+"' method='post'><a href='javascript:form"+(i+7)+".submit()' class='btn_buy' >取消</a></form>");}
package serv.BD;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import dao.BD.daoBDReserve;import dao.BD.daoBDReserveDetail;import dao.DT.daoDTRoomType;import vo.BD.voBDReserve;import vo.BD.voBDReserveDetail;import vo.DT.voDTRoomType;@SuppressWarnings("serial")public class servBDReserveShow extends HttpServlet { public servBDReserveShow() { super(); } public void destroy() { super.destroy(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset==utf-8"); request.setCharacterEncoding("gb2312"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); ArrayList<voBDReserve> ReserveList=new ArrayList<voBDReserve>(); daoBDReserve daoBDReserve = new daoBDReserve(); daoBDReserveDetail daoBDReserveDetail = new daoBDReserveDetail(); String membernum=request.getParameter("mnum"); ReserveList=daoBDReserve.showReserve(membernum); if(membernum!=null){ out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println("<head>"); out.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"); out.println("<title>Reserve</title>"); out.println("<link href='../ky/css/style.css' rel='stylesheet' type='text/css' media='all' />"); out.println("<link href='../ky/css/font.css' rel='stylesheet' type='text/css'>"); out.println("<link href='../ky/css/new.css' rel='stylesheet' type='text/css' media='all' />"); out.println("</head>"); out.println("<body>"); out.println("<div class='header'>"); out.println("<div class='header-left-w'>"); out.println("<div class='logo'>"); out.println("<a href='../ky/index.jsp?mnum="+membernum+"'><img src='../ky/images/logo.png' alt="web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose" ></a>"); out.println("</div>"); out.println("<div class='top-nav'>"); out.println("<ul >"); out.println("<li><a href='../ky/index.jsp?mnum="+membernum+"' >主页</a></li>"); out.println("<li><a href='../ky/intro.jsp?mnum="+membernum+"' class='black' > 简介</a></li>"); out.println("<li><form name='form1' action='/g0103/servlet/servDTRoomTypeShow?mnum="+membernum+"' method='post'><a href='javascript:form1.submit()' class='black1'> 预定</a></form></li>"); out.println("<li class='active' ><form name='form2' action='/g0103/servlet/servBDReserveShow?mnum="+membernum+"' method='post'><a href='javascript:form2.submit()' class='black1'> 预定信息</a></form></li>"); out.println("<li><form name='form3' action='/g0103/servlet/servBEMemberShow?mnum="+membernum+"' method='post'><a href='javascript:form3.submit()' class='black1'> 会员信息</a></form></li>"); out.println("<li><a href='../ky/login.jsp' class='black4' > 登录</a></li>"); out.println("</ul>"); out.println("</div>"); out.println("</div>"); out.println("<div class='header-top'>"); out.println("<div class='logo-in'>"); out.println("<a href='../ky/index.jsp?mnum="+membernum+"'><img src=../ky/images/logo.png alt="web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose" ></a>"); out.println("</div>"); out.println("<div class='top-nav-in'>"); out.println("<span class='menu'><img src='../ky/images/menu.png' alt="web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose" > </span>"); out.println("<ul >"); out.println("<li><a href='../ky/index.jsp?mnum="+membernum+"' >主页</a></li>"); out.println("<li><a href='../ky/intro.jsp?mnum="+membernum+"' class='black' > 简介</a></li>"); out.println("<li><form name='form4' action='/g0103/servlet/servDTRoomTypeShow?mnum="+membernum+"' method='post'><a href='javascript:form4.submit()' class='black1'> 预定</a></form></li>"); out.println("<li class='active' ><form name='form5' action='/g0103/servlet/servBDReserveShow?mnum="+membernum+"' method='post'><a href='javascript:form5.submit()' class='black1'> 预定信息</a></form></li>"); out.println("<li><form name='form6' action='/g0103/servlet/servBEMemberShow?mnum="+membernum+"' method='post'><a href='javascript:form6.submit()' class='black1'> 会员信息</a></form></li>"); out.println("<li><a href='../ky/login.jsp?mnum="+membernum+"' class='black4' > 登录</a></li>"); out.println("<form name='form7'action='/g0103/servlet/servBDReserveCancel?rnum="+ReserveList.get(0).getReserveNum()+"' method='post'></form>"); out.println("</ul>"); out.println("<script>"); out.println("$('span.menu').click(function(){"); out.println("$('.top-nav-in ul').slideToggle(500, function(){"); out.println("});"); out.println("});"); out.println("</script>"); out.println("</div>"); out.println("<div class='clear'> </div>"); out.println("</div>"); for(int i=0;i< ReserveList.size();i++) { voBDReserve voBDReserve0 = new voBDReserve(); voBDReserve0=ReserveList.get(i); voBDReserveDetail voBDReserveDetail0 = new voBDReserveDetail(); voBDReserveDetail0=daoBDReserveDetail.showReserveDetail(voBDReserve0.getReserveNum()); voDTRoomType voRoomType=new voDTRoomType(); daoDTRoomType daoRoomType=new daoDTRoomType(); voRoomType=daoRoomType.finDTRoomType(voBDReserveDetail0.getTypeNum()); out.println("<div class='content'>"); out.println("<div class='work'>"); out.println("<div class='htl_room_list_box'>"); out.println("<ul class='htl_room_list'>"); out.println("<div class='htl_room_info'>"); out.println("<h4>订单"+(i+1)+"</h4>"); out.println("<p class='info'><span class='divide'>|</span>订单号:"+voBDReserve0.getReserveNum()+"</p>"); out.println(" <table class='htl_room_tb'>"); out.println("<tbody>"); out.println("<tr>"); out.println("<th></th>"); out.println("<th>订单状态</th>"); out.println("<th>入住时间</th>"); out.println("<th>入住天数</th>"); out.println("<th>房间类型</th>"); out.println("<th>总价<strong></strong></th>"); out.println("<th class='th_room_booking'></th>"); out.println("</tr>"); out.println("<tr class='J_needHidePrice'> "); out.println("<td>明细</span></td>"); out.println("<td>"+voBDReserveDetail0.getResstateNum()+"</td>"); out.println("<td>"+voBDReserveDetail0.getCheckInTime()+"</td>"); out.println("<td>"+voBDReserveDetail0.getStayDays()+"</td>"); out.println("<td>"+voRoomType.getTypeName()+"</span></td>"); out.println("<td>"+voBDReserve0.getFontMoney()+"元</span></td>"); out.println("<td>"); out.println("<a href='javascript:form"+(i+7)+".submit()' class='btn_buy' >取消</a>"); out.println("</td>"); out.println("</tr>"); out.println("</tbody>"); out.println("</table>"); out.println("</div>"); out.println("</ul>"); out.println(" "); out.println("</div>"); out.println("</div>"); out.println("</div>"); out.println("</div>"); out.println("</body>"); out.println("</html>"); } } } }
你应该到JavaEE模块里去问这个问题,移步 http://bbs.csdn.net/forums/J2EE。
另外,你都说了是 MVC, view和model分离:
页面HTML内容应该在JSP中写,
在servlet中把 ReserveList对象传过去用EL、JSTL展示即可。
至于你遇到的问题,你可以使用Ajax,而不直接使用Form提交表单的方式;
像一般的列表页,每个行(item)都有个删除的按钮,点击删除按钮,
就通过Ajax把这个item的ID传到服务器进行删除,然后反馈等等。
你把每个订单都用