<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" session="false"%>
<!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>
<%
//创建一个cookie
Cookie cookie = new Cookie("name","wyf");
response.addCookie(cookie);
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" session="false"%>
<!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>
<%
Cookie[] cookies = request.getCookies();
if(cookies !=null && cookies.length>0){
for(Cookie cookie : cookies){
out.print(cookie.getName()+":"+cookie.getValue());
}
}else{
out.print("没有cookie,正在创建,并且返回");
Cookie cookie = new Cookie("name","wyf");
response.addCookie(cookie);
}
%>
</body>
</html>
<%
Cookie[] cookies = request.getCookies();
if(cookies !=null && cookies.length>0){
for(Cookie cookie : cookies){
out.print(cookie.getName()+":"+cookie.getValue());
}
}else{
out.print("没有cookie,正在创建,并且返回");
Cookie cookie = new Cookie("name","wyf");
cookie.setMaxAge(30);
response.addCookie(cookie);
}
%>
<%@ 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> <form action="success.jsp" method="post"> name:<input type="text" name="name"/> <input type="submit" value="sumit"/> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" session="false"%>
<!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>
<%
//若可以获取到参数name,则打印登录信息,将信息存储到cookie中,并设置cookei的时间
String name = request.getParameter("name");
if (name != null && !name.trim().equals("")) {
Cookie cookie = new Cookie("nameCookie", name);
cookie.setMaxAge(60);
response.addCookie(cookie);
} else {
//如果没有参数,可以用cookie登录,从cookie中读取用户信息,如果存在则打印欢迎信息
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
if ("nameCookie".equals(cookieName)) {
String val = cookie.getValue();
name = val;
}
}
}
}
if (name != null && !name.trim().equals("")) {
out.print("hello" + name);
} else {
//若没有请求参数,也没有cookie,则重定向到login.jsp
response.sendRedirect("login.jsp");
}
%>
</body>
</html>
<%@ 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>
<h4>Books Page</h4>
<a href="book.jsp?book=JavaWeb">JavaWeb</a>
<a href="book.jsp?book=Java">Java</a>
<a href="book.jsp?book=Oracle">Oracle</a>
<a href="book.jsp?book=Ajax">Ajax</a>
<a href="book.jsp?book=JavaScript">JavaScript</a>
<a href="book.jsp?book=Android">Android</a>
<a href="book.jsp?book=Jbpm">Jbpm</a>
<br><br>
<%
//获取所有的Cookie
Cookie[] cookies = request.getCookies();
//从筛选出的Book的Cookie,如果cookieName为ATGUIGU_BOOK_ 开头的即符合条件
if(cookies!=null&&cookies.length>0){
for(Cookie c:cookies){
String cookieName = c.getName();
if(cookieName.startsWith("Safly")){
//显示cookieValue
out.println(c.getValue());
out.print("<br>");
}
}
}
%>
</body>
</html>
<%@page import="java.util.ArrayList"%>
<%@ 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>
Book:<%= request.getParameter("book") %>
<br><br>
<a href="books.jsp">return</a>
<%
String book = request.getParameter("book");
//确定要被删除的Cookie
Cookie[] cookies = request.getCookies();
//保存所有Safly 开头的Cookie
ArrayList<Cookie> bookCookies = new ArrayList<Cookie>();
//用来保存和books.jsp 传入的book匹配的那个Cookie
Cookie tempCookie = null;
if(cookies!=null&&cookies.length>0){
for(Cookie c:cookies){
String cookieName = c.getName();
if(cookieName.startsWith("Safly")){
bookCookies.add(c);
//选购5个之后,在选5个中的一个
if(c.getValue().equals(book)){
out.print("c.getValue().equals(book)");
tempCookie = c;
}
}
}
}
//选购5个选除这5本以外的一本
if(bookCookies.size() >= 5&&tempCookie == null){
tempCookie = bookCookies.get(0); //
out.print("tempCookie == null");
}
//若在其中则删除bookCookie本身,将列表的重复cookie删掉,并且将其回传
if(tempCookie != null){
tempCookie.setMaxAge(0);
response.addCookie(tempCookie);
}
//把从books.jsp传入的book作为一个Cook返回
Cookie cook = new Cookie("Safly"+book,book);
response.addCookie(cook);
%>
</body>
</html>
Cookie cook = new Cookie("Safly"+book,book);
response.addCookie(cook);
if(cookieName.startsWith("Safly")){
bookCookies.add(c);}
tempCookie.setMaxAge(0); response.addCookie(tempCookie);
<%@ 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 cookieValue = null;
Cookie [] cookies = request.getCookies();
if(cookies!=null&& cookies.length>0){
for(Cookie cookie:cookies){
if("cookiePath".equals(cookie.getName())){
cookieValue = cookie.getValue();
}
}
}
if(cookieValue != null){
out.print(cookieValue);
}else{
out.print("没有指定的cookie");
}
%>
</body>
</html>
<%@ 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>
<%
//可以作用当前目录,和当前目录的子目录,但不能作用于当前目录的上一级目录
//可以通过setPath设置cookie的作用范围,/代表站点的根目录
Cookie cookie = new Cookie("cookiePath","CookiePathValue");
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
%>
<a href="../cookie2.jsp">to cookie2.jsp</a>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有