疑问:表单中的内容提交后,接收不到。
问题详细描述:
1、我在viewcart.jsp里装载了updatecat.jsp页面,updatecat.jsp用来更新购物车的数量业务逻辑;
2、viewcart.jsp是展示购物车中的内容,修改数量后,点击提交,将表单中的数据传到updatecat.jsp中进行更新。
3、
在updatecart.jsp中用request接收到的参数只有提交按钮的信息(<input type="submit" name="submit" value="保存修改" />),没有我想要的信息(<input type="text" name="${dish.dishid}" value="${item.quantity}" />)
4、貌似错误很明显,因为我用myeclipse自带的tomcat时还可以运行,到改为tomcat6时,就出错了,或许和这个没关系,但总之,我很无语呀……。
页面设置如下:
购物车展示页面:viewcart.jsp<%@ page language="java" contentType="text/html; charset=GBK"
import="java.util.Map,java.util.Set,j2ee.domain.CartItemBean,j2ee.domain.Cart,j2ee.domain.Dish" pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 获取session中的cart --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>显示购物车</title>
</head>
<body>
<%-- 加载更新数量和删除菜单项的JSP页面 --%>
<jsp:include page="updatecart.jsp" flush="false"/>
<jsp:include page="delitemfromcart.jsp" flush="false"/>
<form name="viewform" action="viewcart.jsp" method="post">
<table width="100%" border="0" align="CENTER" cellpadding="2"
cellspacing="1" bgcolor="#c0c0c0">
<tr bgcolor="#dadada">
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">编号</font>
</div>
</td>
<td width="100" height="22">
<div align="CENTER">
<font color="#000000">菜名</font>
</div>
</td>
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">单价</font>
</div>
</td>
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">数量</font>
</div>
</td>
<td width="36" height="22">
<div align="CENTER">
<font color="#000000">金额</font>
</div>
</td>
<td width="36" height="22">
<div align="CENTER">
<font color="#000000">操作</font>
</div>
</td>
</tr><c:set var="cart" value="${sessionScope.CART}" scope="session"/>
<c:if test="${cart!=null}">
<c:set var="totalprice" value="${0.0+0.0}"/>
<c:forEach var="entry" items="${cart}">
<c:set var="item" value="${entry.value}"/>
<c:set var="totalprice" value="${totalprice+item.totalprice}"/>
<c:set var="dish" value="${item.dish}"/>
<tr bgcolor="#ffffff">
<td width="36" align="center" height="22">
<font color="#000000">${dish.dishid}</font>
</td>
<td width="100" height="22">
<font color="#000000">${dish.dishname}</font>
</td>
<td width="36" align="center" height="22">
<font color="#000000">${dish.nowprice}</font>
</td>
<td width="36" class="hh" align="center" height="22">
<input type="text" name="${dish.dishid}" value="${item.quantity}" />
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000">${item.totalprice}</font>
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000"><a href="viewcart.jsp?delid=${dish.dishid}">删除</a>
</font>
</td>
</tr> </c:forEach>
<tr>
<td width="36" class="bb" align="center" height="22">
<font color="#000000">总价</font>
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000"><c:out value="${totalprice}"/></font>
</td>
</tr>
</c:if>
</table>
<input type="submit" name="submit" value="保存修改" />
<a href="show.jsp">继续购物</a>
<a href="settle?total=${totalprice}">结算</a>
</form>
</body>
</html>
更新数量的页面updatecart.jsp<%@ page language="java" import="java.util.*,j2ee.domain.*" pageEncoding="GBK"%>
<jsp:useBean id="CART" scope="session" class="j2ee.domain.Cart"></jsp:useBean>
<%
request.setCharacterEncoding("GBK");
String submit = null;
submit = request.getParameter("submit");
if (submit != null && submit.equals("保存修改")) {
ArrayList<Dish> dishs=(ArrayList<Dish>)session.getAttribute("DISHS");
Enumeration e=request.getParameterNames();
while(e.hasMoreElements()){
String s=(String)e.nextElement();
System.out.println(s);
System.out.println(request.getParameter(s));
}
System.out.println("--------------");
for (int i = 1; i <= dishs.size(); i++) {
String sno=request.getParameter(String.valueOf(i));
if (sno != null) {
int quantity = Integer.parseInt(sno);
System.out.println(i+","+quantity);
CART.updateItem(i, quantity);
}
} session.setAttribute("CART", CART);
}
%>
问题详细描述:
1、我在viewcart.jsp里装载了updatecat.jsp页面,updatecat.jsp用来更新购物车的数量业务逻辑;
2、viewcart.jsp是展示购物车中的内容,修改数量后,点击提交,将表单中的数据传到updatecat.jsp中进行更新。
3、
在updatecart.jsp中用request接收到的参数只有提交按钮的信息(<input type="submit" name="submit" value="保存修改" />),没有我想要的信息(<input type="text" name="${dish.dishid}" value="${item.quantity}" />)
4、貌似错误很明显,因为我用myeclipse自带的tomcat时还可以运行,到改为tomcat6时,就出错了,或许和这个没关系,但总之,我很无语呀……。
页面设置如下:
购物车展示页面:viewcart.jsp<%@ page language="java" contentType="text/html; charset=GBK"
import="java.util.Map,java.util.Set,j2ee.domain.CartItemBean,j2ee.domain.Cart,j2ee.domain.Dish" pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 获取session中的cart --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>显示购物车</title>
</head>
<body>
<%-- 加载更新数量和删除菜单项的JSP页面 --%>
<jsp:include page="updatecart.jsp" flush="false"/>
<jsp:include page="delitemfromcart.jsp" flush="false"/>
<form name="viewform" action="viewcart.jsp" method="post">
<table width="100%" border="0" align="CENTER" cellpadding="2"
cellspacing="1" bgcolor="#c0c0c0">
<tr bgcolor="#dadada">
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">编号</font>
</div>
</td>
<td width="100" height="22">
<div align="CENTER">
<font color="#000000">菜名</font>
</div>
</td>
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">单价</font>
</div>
</td>
<td height="22" width="36">
<div align="CENTER">
<font color="#000000">数量</font>
</div>
</td>
<td width="36" height="22">
<div align="CENTER">
<font color="#000000">金额</font>
</div>
</td>
<td width="36" height="22">
<div align="CENTER">
<font color="#000000">操作</font>
</div>
</td>
</tr><c:set var="cart" value="${sessionScope.CART}" scope="session"/>
<c:if test="${cart!=null}">
<c:set var="totalprice" value="${0.0+0.0}"/>
<c:forEach var="entry" items="${cart}">
<c:set var="item" value="${entry.value}"/>
<c:set var="totalprice" value="${totalprice+item.totalprice}"/>
<c:set var="dish" value="${item.dish}"/>
<tr bgcolor="#ffffff">
<td width="36" align="center" height="22">
<font color="#000000">${dish.dishid}</font>
</td>
<td width="100" height="22">
<font color="#000000">${dish.dishname}</font>
</td>
<td width="36" align="center" height="22">
<font color="#000000">${dish.nowprice}</font>
</td>
<td width="36" class="hh" align="center" height="22">
<input type="text" name="${dish.dishid}" value="${item.quantity}" />
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000">${item.totalprice}</font>
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000"><a href="viewcart.jsp?delid=${dish.dishid}">删除</a>
</font>
</td>
</tr> </c:forEach>
<tr>
<td width="36" class="bb" align="center" height="22">
<font color="#000000">总价</font>
</td>
<td width="36" class="bb" align="center" height="22">
<font color="#000000"><c:out value="${totalprice}"/></font>
</td>
</tr>
</c:if>
</table>
<input type="submit" name="submit" value="保存修改" />
<a href="show.jsp">继续购物</a>
<a href="settle?total=${totalprice}">结算</a>
</form>
</body>
</html>
更新数量的页面updatecart.jsp<%@ page language="java" import="java.util.*,j2ee.domain.*" pageEncoding="GBK"%>
<jsp:useBean id="CART" scope="session" class="j2ee.domain.Cart"></jsp:useBean>
<%
request.setCharacterEncoding("GBK");
String submit = null;
submit = request.getParameter("submit");
if (submit != null && submit.equals("保存修改")) {
ArrayList<Dish> dishs=(ArrayList<Dish>)session.getAttribute("DISHS");
Enumeration e=request.getParameterNames();
while(e.hasMoreElements()){
String s=(String)e.nextElement();
System.out.println(s);
System.out.println(request.getParameter(s));
}
System.out.println("--------------");
for (int i = 1; i <= dishs.size(); i++) {
String sno=request.getParameter(String.valueOf(i));
if (sno != null) {
int quantity = Integer.parseInt(sno);
System.out.println(i+","+quantity);
CART.updateItem(i, quantity);
}
} session.setAttribute("CART", CART);
}
%>
解决方案 »
- 【100分】怎么知道浏览器已关闭?
- 关于错误500的问题二,在线等
- struts2 上传时报错,求教原因?
- Spring ibatis 问题 请教高手
- 怎么使用openoffice实现online edit功能啊?
- 求struts连接sqlserver2000数据库的struts-config.xml(jtds-1.2.jar驱动)
- 数据库连接问题~~~~~~~~~~
- import javax.jws.WebMethod时出错
- 单一登陆,用户锁定。商讨解决方案 (跟贴有分)
- 高手请进!
- mysql连接失败
- Exception in thread "main" java.lang.UnsatisfiedLinkError
==>
name="dishID_${dish.dishid}"
dishID_是我加的
以上是我个人的理解,以前好像遇到过这样的问题