1.最初的页面
SetCookie.jsp
<%@ 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>SetCookie</title> </head> <body> <% Cookie c1 = new Cookie("name","java"); Cookie c2 = new Cookie("password","123"); c1.setMaxAge(180);//秒 c2.setMaxAge(180);//秒 response.addCookie(c1); response.addCookie(c2); %> <jsp:forward page="GetCookie.jsp"></jsp:forward> </body> </html>getCookie.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.io.PrintWriter"%> <!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>GetCookie</title> </head> <body> <% //PrintWriter pw = response.getWriter(); for(Cookie tem : request.getCookies()){ // pw.print(tem.getName()+tem.getValue()); out.print(tem.getName()+tem.getValue()); } %> </body> </html>
然后我就想request.getCookies()为空我就改成
<body> <%=request.getCookies()==null%> </body>
Expecting "jsp:param" standard action with "name" and "value" attributes
有个csdn的同志说是因为
<jsp:forward page="GetCookie.jsp"></jsp:forward>
得这样写
<jsp:forward page="GetCookie.jsp">
<jsp:param name="" value=""/>
</jsp:forward>
果然正确
但是页面显示为true
我想是不是当开始标签和闭合标签中没有内容的话 应该标准一点写成<jsp:forward page="GetCookie.jsp"/>
结果页面显示为false
看此,我赶紧吧getCookie.jsp复原
然后显示正确
更蛋疼的是我把所有复原后竟然也正确了.......让人纠结
但是告诉我们一个道理,运行不出来时不一定是咱的代码错误,有时要靠天时.但这句话是令我很不喜欢的