运行jsp出现错误Unable to compile class for JSP

Luuuuuuuuu 2017-12-25 09:43:18
An error occurred at line: 34 in the jsp file: /shoppingcart.jsp
Collection cannot be resolved to a type
31: <%
32: int i_totalnum=0;
33: double d_totalamount=0.0;
34: Collection c_cart=(Collection)session.getAttribute("cart");
35: Iterator it=null;
36: if(c_cart!=null&&c_cart.size()>0){%>
37: <tr>


全部代码
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<body>
<div align="center">
<table width="750" border="0" cellspacing="1" cellpadding="1">
<tr>
<td ><div align="center"><%@include file="top.jsp" %></div></td>
</tr>
<tr>
<td ><div align="center">
<table width="100%" border="0" cellpadding="1" cellspacing="1" class="td">
<tr>
<td colspan="7">购物车</td>
</tr>
<tr>
<td colspan="7"><hr size="1" noshade width="100%"></td>
</tr>
<%
int i_totalnum=0;
double d_totalamount=0.0;
Collection c_cart=(Collection)session.getAttribute("cart");
Iterator it=null;
if(c_cart!=null&&c_cart.size()>0){%>
<tr>
<td>产品编号号</td>
<td>品名</td>
<td>原产地</td>
<td>单价</td>
<td>数量(件)</td>
<td>合价</td>
<td>操作</td>
</tr>
<%
it=c_cart.iterator();
while(it.hasNext()){
cartBean cbean=(cartBean)(it.next());
i_totalnum+=cbean.ordernum;
d_totalamount+=cbean.subtotal;
%>
<tr>
<td height="19"><a href="bookdetail.jsp?bookid=<%=cbean.bookid%>" target="_blank"><%=cbean.bookid%></a></td>
<td><%=cbean.bookname%></td>
<td><%=cbean.publish%></td>
<td>¥<%=cbean.unitprice%></td>
<td><input type="text" class="formtext" value="<%=cbean.ordernum%>" size="5" readonly> 
<input type="button" onClick="MM_goToURL('parent','increaseCart.jsp?bookid=<%=cbean.bookid%>');return document.MM_returnValue" value="+"> 
<input type="button" onClick="MM_goToURL('parent','decreaseCart.jsp?bookid=<%=cbean.bookid%>');return document.MM_returnValue" value="-"></td>
<td>¥<%=cbean.subtotal%></td>
<td><a href="delfromcart.jsp?bookid=<%=cbean.bookid%>">取消</a></td>
</tr>
<% }//while%>
<tr>
<td colspan="4"><div align="right">合计</div></td>
<td ><%=i_totalnum%>(本)</td>
<%
d_totalamount=Math.round(d_totalamount*100)/100.00;
%>
<td colspan="2">¥<%=d_totalamount%></td>
</tr>
<tr>
<td colspan="7"> <div align="center">
<input type="button" onClick="MM_goToURL('parent','clearcart.jsp');return document.MM_returnValue" value=" 清空购书车 ">   
<input type="button" onClick="MM_goToURL('parent','index.jsp');return document.MM_returnValue" value=" 继续购书 ">  
<input type="button" onClick="MM_goToURL('parent','order1.jsp');return document.MM_returnValue" value=" 去收银台 ">
</div></td>
</tr>
<%}else{%>
<tr>
<td colspan="7"> <div align="center">您的购物车为空!</div></td>
</tr>
<% }//else%>
</table>
</div></td>
</tr>
<tr>
<td ><div align="center"><%@include file="bottom.jsp" %></div></td>
</tr>
</table>
</div>
</body>
</html>
...全文
188 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
什么都不能 2017-12-26
  • 打赏
  • 举报
回复
Collection 需要import进来,或者代码里带上命名空间
Dan_当真 2017-12-25
  • 打赏
  • 举报
回复
我看不出来, 你用ArrayList 或者HashSet 试试, 不知道的时候就假想下
Luuuuuuuuu 2017-12-25
  • 打赏
  • 举报
回复
具体用什么子类呢
Dan_当真 2017-12-25
  • 打赏
  • 举报
回复
Collection 是属于接口, 你从session中得到cart 应该是个集合,应该用它的子类来替代 Collection XXXXXXXXc_cart=(XXXXXXXX)session.getAttribute("cart");

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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