jsp session
程序员文章站
2022-03-14 23:47:38
...
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.io.*,java.util.*,java.text.*" %>
<!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>
<%
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dNow = new Date(session.getCreationTime()); //session创建时间
session.setMaxInactiveInterval(60);//设置session过期时间,60秒
session.setAttribute("username", "zhangsan");//设置session变量
session.setAttribute("userid", 13);//设置session变量
out.println("session创建时间:"+ft.format(dNow)+"<br>");
out.println("sessionid:"+session.getId()+"<br>");
out.println("userid:"+session.getAttribute("userid")+"<br>");
out.println("username:"+session.getAttribute("username")+"<br>");
session.removeAttribute("username");//删除session变量
out.println("username:"+session.getAttribute("username")+"<br>");
out.println("session过期时间:"+session.getMaxInactiveInterval()+"秒");
session.invalidate();//删除整个会话
%>
</body>
</html>
转载于:https://my.oschina.net/tongjh/blog/712819
上一篇: 【jsp】session