| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 913 人关注过本帖
标题:做购物车JSP页面时出错了
取消只看楼主 加入收藏
huanwei50
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-10-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
做购物车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.
<html xmlns="http://www.
    <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 页面 
2010-11-22 13:06
huanwei50
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-10-31
收藏
得分:0 
回复 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();

我是直接运行这个界面的  是不是应为没有登录啊  没有值  
 
2010-11-22 13:52
huanwei50
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-10-31
收藏
得分:0 
回复 4楼 筱晓绾
OK了    谢了
2010-11-22 15:23
快速回复:做购物车JSP页面时出错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029866 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved