求教:表单内容提交失败的原因

只要开始永远不晚 2012-05-20 02:25:11
疑问:表单中的内容提交后,接收不到。
问题详细描述:
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);
}
%>
...全文
542 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
古布 2012-05-20
  • 打赏
  • 举报
回复
这是HTML的问题,纯数字不是合法的标志符。不能用合法的name, 如果你做了,便不会提交。
以上是我个人的理解,以前好像遇到过这样的问题
  • 打赏
  • 举报
回复
嗯,看到了,试了一下,输出了,为什么不加几个字符,它不给提交呢?
古布 2012-05-20
  • 打赏
  • 举报
回复
name="${dish.dishid}"
==>
name="dishID_${dish.dishid}"
dishID_是我加的
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

<input type="text" name="${dish.dishid}" value="${item.quantity}" />

==》

<input type="text" name="dishID_${dish.dishid}" value="${item.quantity}" />

前面加几个字母试试。
[/Quote]
请问:你说的是在哪里加几个字母?
古布 2012-05-20
  • 打赏
  • 举报
回复
<input type="text" name="${dish.dishid}" value="${item.quantity}" />

==》

<input type="text" name="dishID_${dish.dishid}" value="${item.quantity}" />

前面加几个字母试试。

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧