<%@page import="java.net.URLDecoder"%> <%@ page language="java" contentType="text/html; charset=UTF-8" 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"> <title>Insert title here</title> </head> <body> <% String name = null; Cookie[] ck = request.getCookies(); //获取cookie集合 for(Cookie cks:ck){ if(cks.getName().equals("name")){ name = cks.getValue(); } } %> <form action="shop.jsp" method="post"> 卡号:<input type="text" name="name" value="<% if(name != null){out.print(name);}%>"><br> 密码:<input type="password" name="password"><br> <input type="submit" value="登录"> </form> </body> </html>
<%@page import="java.net.URLEncoder"%> <%@ page language="java" contentType="text/html; charset=UTF-8" 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"> <title>Insert title here</title> </head> <body> <% String name = request.getParameter("name"); //创建cookie Cookie coo = new Cookie("name",name); coo.setMaxAge(60*60*24);//设置过期时间 response.addCookie(coo); out.print("登入成功"); %> <br> <form action="shopbox.jsp"method="post"> <input type="checkbox"name="name1"value="gangbi"/>钢笔<br> <input type="checkbox"name="name2"value="xie"/>鞋<br> <input type="checkbox"name="name3"value="shangyi"/>上衣<br> <input type="submit"value="添加至购物车"> </form> 您的购物车: <% Cookie[] mcc = request.getCookies(); //获取cookie集合 for(Cookie ok:mcc){ if(ok.getName().equals("name1")){ out.print(ok.getValue()+"<br>"); } } Cookie[] mcc1 = request.getCookies(); //获取cookie集合 for(Cookie ok1:mcc1){ if(ok1.getName().equals("name2")){ out.print(ok1.getValue()+"<br>"); } } Cookie[] mcc2 = request.getCookies(); //获取cookie集合 for(Cookie ok2:mcc2){ if(ok2.getName().equals("name3")){ out.print(ok2.getValue()+"<br>"); } } %> </body> </html>
<%@page import="java.net.URLDecoder"%> <%@page import="java.net.URLEncoder"%> <%@ page language="java" contentType="text/html; charset=UTF-8" 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"> <title>Insert title here</title> </head> <body> <% String name1 =request.getParameter("name1"); String name2 = request.getParameter("name2"); String name3 = request.getParameter("name3"); Cookie cks1= new Cookie("name1",name1); response.addCookie(cks1); cks1.setMaxAge(60*60*24);//设置过期时间 Cookie cks2= new Cookie("name2",name2); response.addCookie(cks2); cks2.setMaxAge(60*60*24);//设置过期时间 Cookie cks3= new Cookie("name3",name3); response.addCookie(cks3); cks3.setMaxAge(60*60*24);//设置过期时间 out.print("您的物品已经添加至购物车"); %> <br> </body> </html>
时间: 2024-10-21 20:37:13