jsp 怎么把存在session里面的购物车订单信息存到数据库
<formmethod="post"action="addorder.do"><a>学院</a><inputtype="text"id="college"maxlengt...
<form method="post" action="addorder.do">
<a>学院</a><input type="text" id="college" maxlength="30" name="college"value=""><br>
<a>班级:</a><input type="text" id="classname" maxlength="30" name="classname" value=""><br>
<a>真实姓名:</a><input type="text" id="chinesename" maxlength="30" name="chinesename"value=""><br>
<a>邮箱:</a><input type="text" id="email" maxlength="30" name="email" value=""><br>
<a>电话:</a><input type="text" id="phone" maxlength="30" name="phone" value=""><br>
<input type="hidden" name="name" value="${sessionScope.user.name}">
<c:forEach var="item" items="${sessionScope.cart.items}">
<input type="hidden" name="title" value="${item.title.title}">
<input type="hidden" name="amcount" value="${item.amcount}">
<input type="hidden" name="subtotal" value="${item.subtotal}">
</c:forEach>
<input type="submit" value="提交订单">
</form>
这是提交的表单,单session里面只有一条记录时,是可以存到数据库里,但是有多条数据时,存到数据库里的只有第一条记录。下面是我的servlet
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = (String) req.getParameter("name");
String college = (String) req.getParameter("college");
String classname = (String) req.getParameter("classname");
String chinesename = (String) req.getParameter("chinesename");
String email = (String) req.getParameter("email");
String phone = (String) req.getParameter("phone");
String title = (String) req.getParameter("title");
String amcount = (String) req.getParameter("amcount");
int count = Integer.parseInt(amcount);
System.out.println(count);
String subtotal = (String) req.getParameter("subtotal");
TitleDAO t = new TitleDAO();
if (count != 0) {
t.addOrder(name, college, classname, chinesename, email, phone,title, amcount, subtotal);
}
}
我想把session里面的信息循环存到数据库中,求高手知道 展开
<a>学院</a><input type="text" id="college" maxlength="30" name="college"value=""><br>
<a>班级:</a><input type="text" id="classname" maxlength="30" name="classname" value=""><br>
<a>真实姓名:</a><input type="text" id="chinesename" maxlength="30" name="chinesename"value=""><br>
<a>邮箱:</a><input type="text" id="email" maxlength="30" name="email" value=""><br>
<a>电话:</a><input type="text" id="phone" maxlength="30" name="phone" value=""><br>
<input type="hidden" name="name" value="${sessionScope.user.name}">
<c:forEach var="item" items="${sessionScope.cart.items}">
<input type="hidden" name="title" value="${item.title.title}">
<input type="hidden" name="amcount" value="${item.amcount}">
<input type="hidden" name="subtotal" value="${item.subtotal}">
</c:forEach>
<input type="submit" value="提交订单">
</form>
这是提交的表单,单session里面只有一条记录时,是可以存到数据库里,但是有多条数据时,存到数据库里的只有第一条记录。下面是我的servlet
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = (String) req.getParameter("name");
String college = (String) req.getParameter("college");
String classname = (String) req.getParameter("classname");
String chinesename = (String) req.getParameter("chinesename");
String email = (String) req.getParameter("email");
String phone = (String) req.getParameter("phone");
String title = (String) req.getParameter("title");
String amcount = (String) req.getParameter("amcount");
int count = Integer.parseInt(amcount);
System.out.println(count);
String subtotal = (String) req.getParameter("subtotal");
TitleDAO t = new TitleDAO();
if (count != 0) {
t.addOrder(name, college, classname, chinesename, email, phone,title, amcount, subtotal);
}
}
我想把session里面的信息循环存到数据库中,求高手知道 展开
展开全部
<s:iterator value="dinnerServiceOuts1" id="dinner1" status="stat">
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].activeMode'}" value="%{dinnerServiceOuts1[#stat.index].activeMode}"/>
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].productID'}" value="%{dinnerServiceOuts1[#stat.index].productID}"/>
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].productName'}" value="%{dinnerServiceOuts1[#stat.index].productName}"/>
</s:iterator>
这样写才成否则你只能得到最后一个值
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].activeMode'}" value="%{dinnerServiceOuts1[#stat.index].activeMode}"/>
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].productID'}" value="%{dinnerServiceOuts1[#stat.index].productID}"/>
<s:hidden name="%{'dinnerServiceOuts1['+#stat.index+'].productName'}" value="%{dinnerServiceOuts1[#stat.index].productName}"/>
</s:iterator>
这样写才成否则你只能得到最后一个值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询