<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" gb2312 "%> <HTML> <body> <% arraylist books = new arraylist (); books. add ("Romance of the Three Kingdoms"); books. add ("Journey to the West"); books. add ("Water Margin"); // put books into the session name book session. setattribute ("book", books ); %> <a href = myjsp2.jsp> View shopping cart </a> </body>
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" gb2312 "%> <HTML> <body> <form action =" myjsp3.jsp "method =" Post "> enter a book: <input name = "book", type = "text"> <input type = "Submit" value = "add to shopping cart"> </form> <HR> <%
// Retrieve the arraylist book = (arraylist) Session named books. getattribute ("books"); If (Book = NULL) // if not, it is the first time {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) ;}%> contents in the shopping cart: <br> <% for (INT I = 0; I <book. size (); I ++ ){
// Retrieve out. println (book. Get (I) + "<br>") ;}%> </body>