博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
【转】轻松记住大端小端的含义(附对大端和小端的解释)
查看>>
设计模式那点事读书笔记(3)----建造者模式
查看>>
ActiveMQ学习笔记(1)----初识ActiveMQ
查看>>
Java与算法之(2) - 快速排序
查看>>
Windows之IOCP
查看>>
WebSocket & websockets
查看>>
openssl 升级
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------&gt;Android嵌入图像InsetDrawable的使用方法
查看>>
Detours信息泄漏漏洞
查看>>