设置session
清除session:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>设置session</title>
</head>
<body>
<%
request.getSession().setAttribute("name","admin");
%>
<a href="index_1.jsp">跳转</a>
</body>
</html>
清除:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>显示session</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<%
String name = (String) request.getSession().getAttribute("name");
%>
<span id="span">当前用户是:<%=name==null?"null":name %></span>
<button id="delSession">点击刷新去除session里的值</button>
<script>
$(function () {
$("#delSession").click(function () {
alert("进来了清除session的方法!")
<%
session.removeAttribute("name");
%>
window.location.href = "index_1.jsp";
})
})
</script>
</body>
</html>