javaWeb购物商城设计---商品详情显示

商品列表显示见:http://blog.csdn.net/u013948010/article/details/78675164
主页面显示商品列表,单击图片进入商品详情:

<a href="goodsDetail.jsp?ID=<%=hot_ID%>">

商品详情数据库表tb_goods:
javaWeb购物商城设计---商品详情显示_第1张图片

建立goodsDetail.jsp页面

访问数据库获取商品

根据页面跳转传递的商品ID访问数据库获得商品详情。


<%
    int typeSystem=0;
    int ID=Integer.parseInt(request.getParameter("ID"));    //获取商品ID
    if(ID>0){
        ResultSet rs=conn.executeQuery("select ID,GoodsName,Introduce,nowprice,picture,"
                                      + " price,typeID from tb_goods where ID=" + ID);  //根据ID查询商品信息
        String goodsName = "";                          //保存商品名称的变量
        float nowprice = (float) 0.0;                       //保存商品现价的变量
        float price = (float) 0.0;                      //保存商品原价的变量
        String picture = "";                                //保存商品图片的变量
        String introduce = "";                          //保存商品描述的变量
        if(rs.next()){
            goodsName=rs.getString(2);
            introduce=rs.getString(3);
            nowprice=rs.getFloat(4);
            picture=rs.getString(5);
            price=rs.getFloat(6);
            typeSystem=rs.getInt(7);
            }
        conn.close();
%>

    
<%}else{//获取到的ID不合法
    out.println("");
        }
%>

相关商品显示

商品详情页面,同时显示同一商品类别的6个同类商品。相关商品显示页面调用relatedGoods.jsp,typeSystem由上文得到为商品类别,根据类别查询数据库。


<div class="mr-module related-products">
    <h3 class="module-title ">相关商品h3>
    
    <jsp:include page="relatedGoods.jsp">
        <jsp:param name="typeSystem" value="<%=typeSystem %>" />
    jsp:include>
    
div>

related.jsp设计

获取类别,初始化变量

<%
    int typeSystem = Integer.parseInt(request.getParameter("typeSystem"));
    int hot_ID = 0;
    String hot_goodsName = "";
    float hot_nowprice = 0;
    String hot_picture = "";
%>

查询数据库

<%
        ResultSet rs_relate = conn.executeQuery(
                "select top 6 ID,GoodsName,nowprice,picture from tb_goods where typeID=" + typeSystem + " ");
        int relate_ID = 0;
        String relate_goodsName = "";
        float relate_nowprice = 0;
        String relate_picture = "";

        int s3 = 0;
        while (rs_relate.next()) {
            relate_ID = rs_relate.getInt(1);
            relate_goodsName = rs_relate.getString(2);
            relate_nowprice = rs_relate.getFloat(3);
            relate_picture = rs_relate.getString(4);
%>
    

详情页面:
javaWeb购物商城设计---商品详情显示_第2张图片
其中左边是热门商品,下面是相关商品

热门商品显示

商品详情页面,同时显示同一商品类别的7个高点击率的人商品。热门商品显示页面调用leftHotGoods.jsp,typeSystem由上文得到为商品类别,根据类别查询数据库,并根据点击量返回商品排序。


<jsp:include page="leftHotGoods.jsp">
<jsp:param name="typeSystem" value="<%=typeSystem %>" />
jsp:include>

leftHotGoods.jsp设计

访问数据库获取热门商品

<%
    int hot_ID = 0;
    String hot_goodsName = "";
    float hot_nowprice = 0;
    String hot_picture = "";
    String sql="";
    if(request.getParameter("type")!=null && request.getParameter("type")!=""){
        int type=Integer.parseInt(request.getParameter("type"));
        sql="select top 7 t1.ID,t1.GoodsName,t1.nowprice,t1.picture from tb_goods t1,tb_subType t2 where t1.typeID=t2.ID and t2.superType="
                + type + " order by t1.hit desc,t1.ID asc";
    }else if(request.getParameter("typeSystem")!=null && request.getParameter("typeSystem")!=""){
        int typeSystem = Integer.parseInt(request.getParameter("typeSystem"));
        sql="select top 7 ID,GoodsName,nowprice,picture from tb_goods where typeID=" + typeSystem
                + " order by hit desc,ID asc";
    }else{
        sql="select top 7 ID,GoodsName,nowprice,picture from tb_goods order by hit desc";
    }
%>

执行查询并显示

"box-product product-grid"> <% ResultSet rs_hot = conn.executeQuery(sql); int s2 = 0; while (rs_hot.next()) { hot_ID = rs_hot.getInt(1); hot_goodsName = rs_hot.getString(2); hot_nowprice = rs_hot.getFloat(3); hot_picture = rs_hot.getString(4); %> <% s2++; } %>

你可能感兴趣的:(java)