1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% OneString name = ""; AString Password = ""; -cookie[] Cookies =request.getcookies (); - if(cookies!=NULL&&cookies.length>0){ the for(Cookie cookie:cookies) { - if("Name". Equals (Cookie.getname ())) { -Name =Cookie.getvalue (); -}Else if("Password". Equals (Cookie.getname ())) { +Password =Cookie.getvalue (); - } + } A } at%> -<form action= "gouwu.jsp" method= "POST" > -Account: <input type= "text" name= "name" value= "<%= name%>"/> -Password: <input type= "password" name= "password" value= "<%= password%>"/> -<input type= "Submit" value= "Submission"/> -</form> in</body> -1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% OneString name = Request.getparameter ("name"); AString Password = request.getparameter ("Password"); -Cookie Cookie1 =NewCookie ("name", name); -Cookie Cookie2 =NewCookie ("password"), password); the Response.addcookie (cookie1); - Response.addcookie (cookie2); - -Object sessionname = Session.getattribute ("name"); + if(sessionname==NULL) -Response.sendredirect ("login.jsp"); +Session.setattribute ("name", name); ASession.setmaxinactiveinterval (60*60); at -%> -<form action= "gouwuresult.jsp" method= "POST" > -Please enter the name of the product you want to buy: <input type= "text" name= "Namesp"/><br/> -Please enter the quantity you want to buy: <input type= "text" name= "number"/><br/> -<input type= "Submit" value= "Submission"/><br/> in</form> -<br/> to<a href= "gouwuchexianshi.jsp" > View items in Cart </a><br/> +<a href= "logout.jsp" > Exit login </a> -</body> the1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% OneObject sessionname = Session.getattribute ("name"); A if(sessionname==NULL) -Response.sendredirect ("login.jsp"); - theOut.print ("items in the shopping cart are as follows:<br/>"); -cookie[] Cookies =request.getcookies (); - if(cookies!=NULL&&cookies.length>0){ - for(intI =0; i<cookies.length;i++){ + if(!cookies[i].getname (). Equals ("name") &&!cookies[i].getname (). Equals ("Password")){ -Out.print (Cookies[i].getname () + "" + cookies[i].getvalue () + "<br/>"); + } A } at}Else{ -Out.print ("Your shopping cart has no goods <br/>"); - } -%> -<a href= "gouwu.jsp" > Back to Shopping page </a> -</body> in1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% One session.invalidate (); AOut.print ("You have logged out"); -%> -<br/> the<a href= "gouwu.jsp" > try back to the shopping page to verify the successful elimination of session</a> -</body> -1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<% OneObject sessionname = Session.getattribute ("name"); A if(sessionname==NULL) - -Response.sendredirect ("login.jsp"); theString Namesp = Request.getparameter ("Namesp"); -String number = Request.getparameter ("number"); -Cookie Cookie1 =NewCookie ("Namesp" +math.random (), NAMESP); -Cookie Cookie2 =NewCookie ("number" +math.random (), number); + Response.addcookie (cookie1); - Response.addcookie (cookie2); + AOut.print ("The item has been added to the shopping cart"); at%> -<br/> -<a href= "gouwu.jsp" > Back to Shopping page </a> -<a href= "gouwuchexianshi.jsp" > View shopping Cart Items </a> -</body> -String Namesp = Request.getparameter ("Namesp"); String number = Request.getparameter ("number"); Cookie cookie1 = new Cookie ("Namesp" +1,NAMESP); Cookie cookie2 = new Cookie ("number" +1,number); Response.addcookie (cookie1); Response.addcookie (COOKIE2);
10-30----work, realize shopping cart, exit login, login Remember user name password, check whether the user logged in 4 functions