1.留言簿页面:liuYan.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8" %> 3 4 <%@ page import= "java.net.URLDecoder" %> 5 6 <%@ page import="java.util.*" %> 7 8 9 10 11留言薄 12 13 14留言薄
15 <%16 Cookie[] co = request.getCookies();17 18 String nc = "";19 String ly = "";20 21 //ArrayListar = new ArrayList<>();22 23 if(co != null)24 {25 for(int i = 0; i < co.length; i++)26 {27 if(co[i].getName().equals("myco"))28 {29 //String mes = "";30 31 nc = URLDecoder.decode(co[i].getValue().split("#")[0]);32 33 ly = URLDecoder.decode(co[i].getValue().split("#")[1]);34 35 //ar.add(mes);36 37 out.print(" 昵称:" + nc +" 留言:" + ly + " ");38 }39 }40 41 /*42 for(int i = 0; i < ar.size(); i ++)43 {44 out.print(" 昵称:" + ar.get(i).split("#") +" 留言:" + ar.get(i).split("#")[1] + " "); 45 }46 */47 }48 else49 {50 out.print("暂时没有留言");51 }52 %>53 54 63 64
2,留言处理页面, xianShi.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8" errorPage="error1.jsp"%> 3 4 <%@ page import="java.net.URLEncoder" %> 5 6 7 8 9 10留言处理页 11 12 13 <%14 //request.setCharacterEncoding("GB18030");15 16 //String nc = URLEncoder.encode(request.getParameter("nc"),"UTF-8");17 String nc = URLEncoder.encode(new String(request.getParameter("nc").getBytes("ISO-8859-1"),"UTF-8"));18 String ly = URLEncoder.encode(new String(request.getParameter("ly").getBytes("ISO-8859-1"),"UTF-8"));19 20 Cookie co = new Cookie("myco",nc + "#" + ly);21 22 co.setMaxAge(60*60*24*30);23 24 response.addCookie(co);25 26 //out.print();27 28 response.sendRedirect("liuYan.jsp");29 %>30 31 32 33