购物车2次改进用session存储

============================dl.html======================
<!-- 登陆界面 -->

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF">
      <center> 欢迎登陆系统</center></br></br>
      <center>
      <form name="login" method="post" action="logcheck.jsp">
          <label>用户名:</label>
          <input type=text name="userID" value="">
          <label>密码:</label>
          <input type=password name="password" value="">
          <input type="submit" name="tj" value="提交"></input>
          <input type="reset" name="reset"></input>
      </form></center>
  </body>
</html>

=================logcheck.jsp=================
<!-- 对dl提交的数据进行判断,跳转zhuce,catalog-->
<%--
    Document   : logcheck
    Created on : 2009-11-9, 20:46:40
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@page import="java.util.*"%>
        <title>登陆</title>
    </head>
    <body>
        <% String promt=new String();
           String Name=request.getParameter("userID");
           String Pass=request.getParameter("password");
                     boolean haslog=false;
           ArrayList names=(ArrayList)session.getAttribute("lognames");
           ArrayList passwords=(ArrayList)session.getAttribute("logpasswords");
                     if(names==null){  %>
               <jsp:forward page="zhuce.html"></jsp:forward>
        <% }
           else{
               for(int i=0;i<names.size();i++){
                    String temp=(String)names.get(i);
                   

                  if(temp.equals(Name)){ %>
                    <jsp:forward page="catalog.jsp"></jsp:forward>
                         <%
                    }
               }
           }
         %>
           </body>
</html>


=======================zhuce.html==============
<!-- 注册信息页面,提交用户资料给getzhuce.jsp-->
<!--
    Document   : zhuce
    Created on : 2009-11-10, 10:26:41
    Author     : Administrator
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body><center>
      <form name="login" method="post" action="getzhuce.jsp">
          <label>用户名:</label>
          <input type=text name="userID" value="">
          <label>密码:</label>
          <input type=password name="password" value="">
          <label>年龄:</label>
          <input type=old name="old" value="">
          <input type="submit" name="tj" value="提交"></input>
          <input type="reset" name="reset"></input>

  </body>
</html>

=====================getzhuce.jsp===============
<%-- 对zhuce提交的信息进行处理用session 存储用户信息--%>
<%--
    Document   : zhuce
    Created on : 2009-11-10, 10:23:47
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>

        <title>注册</title>
    </head>
    <body>
      <%

        String promt=new String();
        String   Name=request.getParameter("userID");
        String   Password=request.getParameter("password");
        ArrayList names=(ArrayList)session.getAttribute("lognames");
 ArrayList passwords=(ArrayList)session.getAttribute("logpasswords");
           if(names==null){
    names=new ArrayList();
           passwords=new ArrayList();
    names.add(Name);
    passwords.add(Password);
    session.setAttribute("lognames",names);
    session.setAttribute("logpassword",passwords);
                  }
         promt="您已完成注册";
      %>
      <%=Name%>,<%=promt%>
    </body>
</html>
==========================catalog.jsp=============
<%--
    Document   : Catalog
    Created on : 2009-11-17, 10:38:28
    Author     : Administrator
购物车选产品界面
--%>

 


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page  import="java.util.HashMap"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
        <title>简单购物车</title>
    </head>
    <body>

<%

        int itemCount=0;
        HashMap cart=(HashMap)session.getAttribute("cart");
        if(cart!=null){
            itemCount=cart.size();
       }
   %>

 


           <table border="0"width ="100%"><tr>
           <td align="left" valign="botom">
            <h1>欢迎来到DOO水果商店挑选水果</h1>
            <form action="cart.jsp" method="POST">
       <table cellspacing="5" cellpadding="5"><tr>
       <td align="center"><b>种类</b></td>
       <td align="center"><B>单价</b></td>
       <td align="center"><B>数量</b></td></tr><tr><br>
       <td align="center">苹果</td>
       <td align="center">5.5</td>
       <td align="center">
       <input name="apple_amount"></td></tr><tr>
       <td align="center">香蕉</td>
       <td align="center">4.5</td>
       <td align="center">
       <input name="banana_amount"></td></tr><tr>
       <td align="center">葡萄</td>
       <td align="center">3.6</td>
       <td align="center">
       <input name="grape_amount"></td></tr><tr>
       <table><hr>
       <input type="Submit" name="btn_submit" value="放入购物车">
       </form>

 

 

 


    </body>
</html>


==========================cart.jsp==================
<%--
    Document   : cart
    Created on : 2009-11-17, 10:39:38
    Author     : Administrator
购物车界面
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page  import="java.util.HashMap"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
        <title>购物车内容</title>

    <body>


   <%

        HashMap cart=(HashMap)session.getAttribute("cart");
        if(cart==null){
             cart=new HashMap();
             cart.put("apple","0");
             cart.put("banana","0");
             cart.put("grape","0");
             session.setAttribute("cart",cart);

        }


            String apple_amount=request.getParameter("apple_amount");
            String banana_amount=request.getParameter("banana_amount");
            String grape_amount=request.getParameter("grape_amount");
        
            String appleAmount=(String)cart.get("apple");
            String bananaAmount=(String)cart.get("banana");
            String grapeAmount=(String)cart.get("grape");
            int new_apple_amount=Integer.parseInt(appleAmount,10)+Integer.parseInt(apple_amount,10);
            int new_banana_amount=Integer.parseInt(bananaAmount,10)+Integer.parseInt(banana_amount,10);
            int new_grape_amount=Integer.parseInt(grapeAmount,10)+Integer.parseInt(grape_amount,10);
            cart.put("apple",String.valueOf(new_apple_amount));
            cart.put("banana",String.valueOf(new_banana_amount));
            cart.put("grape",String.valueOf(new_grape_amount));

         %>
            <h1>你的购物车里有</h1><%=new_apple_amount%>斤苹果 <%=new_banana_amount%>斤香蕉<%=new_grape_amount%>斤葡萄<hr>
       <hr>

<a href="http://localhost:8084/SSSCART/catalog.jsp">回到水果店

 

    </body>
</html>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值