这是index.jsp <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>cookie管理</title> </head> <body> <% String welcome="第一次访问"; String[] info=new String[]{"","",""}; Cookie[] cook=request.getCookies(); if(cook!=null){ for(int i=0;i<cook.length;i++){ if(cook[i].getName().equals("mrCookInfo")){ info=cook[i].getValue().split("#"); welcome="欢迎回来!"; } } } %> <%=info[0]+welcome %> <form action="show.jsp" method="post"> <ul style="line=height:23px"> <li>姓 名:<input name="name" type="text" value="<%=info[0]%>"></li> <li>出生日期:<input name="birthday" type="text" value="<%=info[1] %>"></li> <li>邮箱地址:<input name="mail" type="text" value="<%=info[2]%>"></li> <li><input type="submit" value="提交"> </body> </html>
这是show.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'show.jsp' starting page</title>
</head>
<body>
<%
String name=request.getParameter("name");
String birthday=request.getParameter("birthday");
String mail=request.getParameter("mail");
Cookie myCook=new Cookie("mrCookInfo",name+"#"+birthday+"#"+"mail");
myCook.setMaxAge(60*60*24*365);//设置cookie有效期
response.addCookie(myCook);
%>
表单提交成功
<ul style="line-heigth24px">
<li>姓名:<%=name %>
<li>出生日期<%=birthday %>
<li>电子邮箱<%=mail %>
<li><a href="index.jsp">返回</a>
</ul>
</body>
</html>
问题出在关于cookie管理知识点,show.jsp的代码运行错误提示是第22行
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /show.jsp at line 22 19: String mail=request.getParameter("mail"); 20: Cookie myCook=new Cookie("mrCookInfo",name+"#"+birthday+"#"+"mail"); 21: myCook.setMaxAge(60*60*24*365);//璁剧疆cookie鏈夋晥鏈� 22: response.addCookie(myCook); 23: %> 24: 琛ㄥ崟鎻愪氦鎴愬姛 25: <ul style="line-heigth24px">
丶包菜
相关分类