做购物车JSP页面时出错了
在运行的时候,说Cart不能解决这一类型,错误的句子是:Cart cart = (Cart) request.getSession().getAttribute("cart"); 下面是页面上的代码:<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="com.shop.cart.Cart"%>
<%@ page import="com.shop.dto.product"%>
<%@ page import="java.sql.ResultSet"%>
<%@page import="com.shop.service.productservice"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>购物车</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" href="glCSS/cart.css" type="text/css"></link>
</head>
<body>
<center>
<页面DIV设计。。。。。。。>(省略)
<%
if (request.getSession().getAttribute("username") != null) {
//用户类(用户个人信息)
//得到购物车
Cart cart = (Cart) request.getSession().getAttribute("cart");
Collection<product> collection = cart.getAllproduct();
System.out.println("购买数量为" + collection.size());
Iterator<product> iterator = collection.iterator();
int i = 0;
product products = null;
while (iterator.hasNext()) {
i++;
products = iterator.next();
System.out.println("商品名为" + products.getProductName());
%>
<tr>
<td width="160"><%=i%></td>
<td width="160"><%=products.getProducdID()%></td>
<td width="160"><%=products.getProductName()%></td>
<td width="160"><%=products.getProductClass()%></td>
<td width="160"><%=products.getProductPrice()%></td>
</tr>
<%
}
%>
<%
} else {
System.out.println("XXXXXXXX");
System.out.println("XXXXXXXX");
}
%>
<%
if (request.getSession().getAttribute("cart") != null) {
//得到购物车
Cart cartb = (Cart) request.getSession().getAttribute("cart");
%>
<br>
<tr>
<td width="150"></td>
<td width="150"></td>
<td width="90">
合计总金额:
</td>
<td>
¥
</td>
<td width="150"><%=cartb.getTotalSum()%></td>
</tr>
<%
}
%>
<br>
<tr>
<td width="150"></td>
<td width="90">
<a href="#">返回主页</a>
</td>
<td width="90">
<a href="#">继续购物</a>
</td>
<td width="90">
<a href="#">清空购物车</a>
</td>
<td width="150"></td>
</tr>
</table>
<div>
<hr width="920px" size="2px" noshade="noshade" color="#222">
<br>
<div id="ziti3" class="N5">
Copyright (C) 2004-2009, All Rights Reserved
</div>
</div>
</div>
</center>
</body>
</html>
搜索更多相关主题的帖子:
购物车 JSP 页面
----------------解决方案--------------------------------------------------------
设断点调试没?cart有值没有?报错界面贴出来!
----------------解决方案--------------------------------------------------------
回复 2楼 筱晓绾
An error occurred at line: 65 in the jsp file: /cart/cart.jsp
Cart cannot be resolved to a type
62: if (request.getSession().getAttribute("username") != null) {
63: //用户类(用户个人信息)
64: //得到购物车
65: Cart cart = (Cart) request.getSession().getAttribute("cart");
66: Collection<product> collection = cart.getAllproduct();
67: System.out.println("购买数量为" + collection.size());
68: Iterator<product> iterator = collection.iterator();
我是直接运行这个界面的 是不是应为没有登录啊 没有值
----------------解决方案--------------------------------------------------------
你将登陆界面设为起始页 然后运行 查看下结果
----------------解决方案--------------------------------------------------------
回复 4楼 筱晓绾
OK了 谢了 ----------------解决方案--------------------------------------------------------