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

你可能感兴趣的文章
JPA框架学习
查看>>
JPA、JTA、XA相关索引
查看>>
机器分配
查看>>
php opcode缓存
查看>>
springcloud之Feign、ribbon设置超时时间和重试机制的总结
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>
UIDynamic(物理仿真)
查看>>
Windows下安装Redis
查看>>
winform非常实用的程序退出方法!!!!!(转自博客园)
查看>>
centos安装vim
查看>>
linux工作调度(计划任务)
查看>>
NIO:与 Buffer 一起使用 Channel
查看>>
Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析
查看>>
MFC接收ShellExecute多个参数
查看>>
volatile和synchronized的区别
查看>>
类中的静态函数和非静态函数的区别
查看>>
windows 下安装Apache
查看>>
Fedora14 mount出现错误时解决办法【亲测有效】
查看>>
ruby实现生产者和消费者
查看>>
node.js 之 http 架设
查看>>