码迷,mamicode.com
首页 > 其他好文 > 详细

购物车一

时间:2014-08-08 17:35:06      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   os   io   for   ar   

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
  <body>
    <%
        ArrayList books = new ArrayList();
        books.add("三国演义");
        books.add("西游记");
        books.add("水浒传");
        //将books放进session 名字为book
        session.setAttribute("book",books);
     %>
     <a href=MyJsp2.jsp>查看购物车</a>
  </body>
</html>


<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
 <body>
       购物车内容为:
       <hr>
       <%  
           //从session中取出名为book的 放入数组中
           ArrayList books = (ArrayList)session.getAttribute("book");
           for(int i = 0;i<books.size();i++)
           {
               String book = (String)books.get(i);
               out.println(book + "<BR>");
           }
        %>
  </body>

 

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
 <body>
    <form action = "MyJsp3.jsp" method = "post">
        请你输入书本:<input name ="book", type = "text">
        <input type = "submit" value = " 添加到购物车">
    </form>
    <hr>
    <%
//取出名为books的 ArrayList book = (ArrayList)session.getAttribute("books"); if(book==null) //如果没有 也就是第一次 { out.print("wzz"); book = new ArrayList(); session.setAttribute("books",book); } String book1 = request.getParameter("book"); if(book1!=null) { book1 = new String(book1.getBytes("ISO-8859-1")); book.add(book1); } %> 购物车里的内容:<br> <% for(int i =0;i<book.size();i++) {
//从数组里取出 out.println(book.get(i)
+"<BR>"); } %> </body> </html>

 

购物车一,布布扣,bubuko.com

购物车一

标签:style   blog   color   java   os   io   for   ar   

原文地址:http://www.cnblogs.com/wzz1020/p/3899584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!