博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaWeb——HttpSession常用方法示例
阅读量:4344 次
发布时间:2019-06-07

本文共 2025 字,大约阅读时间需要 6 分钟。

HttpSession接口中方法

getId()

getCreationTime()

getLastAccessedTime()

setMaxInactiveInterval()

getMaxInactiveInterval()

isNew():如果客户端请求消息中返回了一个与Servlet程序当前获得的HttpSession对象的会话标识号相同,则认为这个HttpSession对象不是新建的

invalidate()

getServletContext()

setAttribute()

getAttribute()

removeAttribute()

getAttributeNames()

 

 

login.jsp

<%--  Created by IntelliJ IDEA.  User: dell  Date: 2019/7/10  Time: 15:52  To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %>    Title    SessionID:<%= session.getId()%>
IsNew:<%= session.isNew()%>
MaxInactive:<%=session.getMaxInactiveInterval()%>
CreateTime:<%= session.getCreationTime()%>
LastAssessTime:<%= session.getLastAccessedTime()%>
<% Object username = session.getAttribute("username"); if (username ==null){ username =""; }%>
username:

  

hello.jsp

<%--  Created by IntelliJ IDEA.  User: dell  Date: 2019/7/10  Time: 15:56  To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %>    TitleSessionID:<%= session.getId()%>
IsNew:<%= session.isNew()%>
MaxInactive:<%=session.getMaxInactiveInterval()%>
CreateTime:<%= session.getCreationTime()%>
LastAssessTime:<%= session.getLastAccessedTime()%>
Hello:<%= request.getParameter("username")%>
<% session.setAttribute("username",request.getParameter("username"));%>重新登录
注销

  

logout.jsp

<%--  Created by IntelliJ IDEA.  User: dell  Date: 2019/7/10  Time: 16:07  To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %>    TitleSessionID:<%= session.getId()%>
IsNew:<%= session.isNew()%>
MaxInactive:<%=session.getMaxInactiveInterval()%>
CreateTime:<%= session.getCreationTime()%>
LastAssessTime:<%= session.getLastAccessedTime()%>
BYE:<%= session.getAttribute("username")%>
重新登录<% session.invalidate();%>

转载于:https://www.cnblogs.com/yangHS/p/11164726.html

你可能感兴趣的文章
时钟系统
查看>>
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
linux下wc命令详解
查看>>
敏捷开发中软件测试团队的职责和产出是什么?
查看>>
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>
阶段3 2.Spring_02.程序间耦合_5 编写工厂类和配置文件
查看>>