将内容过程经常用的内容珍藏起来,如下内容是关于JSP设置和获取Cookie的内容。
<%@ page contentType=“text/html;charset=gb2312″%>
<%@ page isELIgnored=“false” %>
<html>
<head>
<title>response测试3-1</title>
</head>
<body>
姓名:<%=request.getParameter(“username”) %><br>
年龄:<%=request.getParameter(“age”) %><br>
<%
String username = request.getParameter(“username”);
String age = request.getParameter(“age”);
Cookie c1 = new Cookie(“username”,username);
Cookie c2 = new Cookie(“age”,age);
response.addCookie(c1);
response.addCookie(c2);
%>
</body>
</html>
获取cookie的jsp页面
<%@ page contentType=“text/html;charset=gb2312″%>
<%@ page isELIgnored=“false” %>
<html>
<head>
<title>response测试3-2</title>
</head>
<body>
<%
Cookie[] cookies = request.getCookies();
for(Cookie c:cookies)
{
out.println(c.getName()+” “+c.getValue()+”<br>”);
}
%>
</body>
</html>
原文地址:https://www.cnblogs.com/chiedboy/p/11263143.html