回顾
会话
什么是HTTP协议?
JSP内置对象 session
引入jsp:指令引入 动作指令引入
<%@ page language="java" contentType="textml; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ include file="common.jsp" %>
<%--
<jsp:include page="common.jsp"></jsp:include>
--%>
欢迎:<%=name %>
<a href="exit.jsp">退出</a>
</body>
<ml>
难过时记得微笑 2019/8/6 9:48:39
<%@ page language="java" contentType="textml; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object name = session.getAttribute("name");
if(name == null){
response.sendRedirect("login.jsp");
}
%>
</body>
<ml>
response 内置对象
out 内置对象
application 内置对象
<%@ page language="java" contentType="textml; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Integer count = (Integer) application.getAttribute("count");
if(count == null){
count = 1;
}else{
count+=1;
}
application.setAttribute("count", count);
%>
<h1>总访问量:<%=count %>次</h1>
</body>
</html>
pageContext 内置对象
config 内置对象
exception 内置对象
page 内置对象
page request session application 作用域
cookie![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7e2b331fc3ee99b14eee8b350914b1f4.png)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Cookie cookie = new Cookie("lastTime",System.currentTimeMillis()+"");
Cookie cookie1 = new Cookie("Time",10+"");
cookie.setMaxAge(10);
cookie1.setMaxAge(10);
response.addCookie(cookie);
response.addCookie(cookie1);
response.sendRedirect("showcookie.jsp");
%>
</body>
</html>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
long time = 0;
int con = 0;
Cookie [] cookies = request.getCookies();
for(Cookie c : cookies){
if(c.getName().equals("lastTime")){
time = Long.valueOf(c.getValue());
con = 1;
}
}
if(con == 0){
out.print("你是第一次登陆,本地存储还没有cookie lastTime");
}else{
out.print("本地存储已有cookie lastTime上次登录时间:"+new Date(time));
}
%>
<hr>
<%
for(Cookie c : cookies){
out.print(c.getName()+" "+c.getValue()+"<br>");
}
%>
</body>
</html>
cookie session 对比
JDBC 回顾
JavaBean
分层