热搜:NVER node 开发 php

web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose

2024-11-06 19:30:01
web开发jsp+java MVC 关于form的一个细节问题_html/css_WEB-ITnose

这是一个订单展示然后有一个按钮取消订单的
这个链接按钮应该是放在form里
但是因为我的订单是从数据库里调的
不知道有多少个订单
所以form也应该是动态生成的
像我这样写可以 只用了一个form 一个订单
要是把form放到循环里就没用了
就是下面这样
ReserveList里面已经存好了多个订单对象

for(int i=0;i< ReserveList.size();i++) {out.println("
取消
");}

该怎么办???
想了好久都没有办法。。。求助


完整代码
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 ReserveList=new ArrayList();			daoBDReserve daoBDReserve = new daoBDReserve();		daoBDReserveDetail daoBDReserveDetail = new daoBDReserveDetail();        String membernum=request.getParameter("mnum");         ReserveList=daoBDReserve.showReserve(membernum);         if(membernum!=null){	        				out.println("");			out.println("");			out.println("");			out.println("");			out.println("Reserve");			out.println("");			out.println("");				out.println("");			out.println("");			out.println("");			out.println("");			out.println("");			out.println("");			out.println("");			out.println("");			out.println("");			out.println("
    "); out.println("
  • 主页
  • "); out.println("
  • 简介
  • "); out.println("
  • 预定
  • "); out.println("
  • 预定信息
  • "); out.println("
  • 会员信息
  • "); out.println("
  • 登录
  • "); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(" "); out.println("
    "); out.println("
  • 主页
  • "); out.println("
  • 简介
  • "); out.println("
  • 预定
  • "); out.println("
  • 预定信息
  • "); out.println("
  • 会员信息
  • "); out.println("
  • 登录
  • "); out.println("
    "); out.println("
"); out.println(""); out.println(""); out.println(" "); out.println(""); 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(""); out.println(""); out.println(""); out.println("
    "); out.println(""); out.println("

    订单"+(i+1)+"

    "); out.println("

    |订单号:"+voBDReserve0.getReserveNum()+"

    "); out.println(" "); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(" "); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
    订单状态入住时间入住天数房间类型总价
    明细"+voBDReserveDetail0.getResstateNum()+""+voBDReserveDetail0.getCheckInTime()+""+voBDReserveDetail0.getStayDays()+""+voRoomType.getTypeName()+""+voBDReserve0.getFontMoney()+"元"); out.println("取消"); out.println("
    "); out.println(""); out.println("
"); out.println(" "); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); } } } }


回复讨论(解决方案)

你应该到JavaEE模块里去问这个问题,移步  http://bbs.csdn.net/forums/J2EE。
另外,你都说了是 MVC, view和model分离:
页面HTML内容应该在JSP中写,
在servlet中把 ReserveList对象传过去用EL、JSTL展示即可。

至于你遇到的问题,你可以使用Ajax,而不直接使用Form提交表单的方式;
像一般的列表页,每个行(item)都有个删除的按钮,点击删除按钮,
就通过Ajax把这个item的ID传到服务器进行删除,然后反馈等等。

你把每个订单都用 

包裹起来,无非就是想和服务器(servlet)进行交换,
把该订单的ID传给服务器进行删除;
和服务器进行交换的方式一般有两种:form表单提交、Ajax。
form表单提交一般用在点击“提交”后会跳转页面或刷新页面的情况;
Ajax一般用在不跳转的情况下(整个页面大体不变的情况下)提交数据给服务器。