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.
--%>
TitleSessionID:
IsNew:
MaxInactive:
CreateTime:
LastAssessTime:
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.
--%>
TitleSessionID:
IsNew:
MaxInactive:
CreateTime:
LastAssessTime:
Hello:
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.
--%>
TitleSessionID:
IsNew:
MaxInactive:
CreateTime:
LastAssessTime:
BYE:
session.invalidate();
%>
这篇博客探讨了如何利用HttpSession接口的方法,如getId()、getCreationTime()和getLastAccessedTime()来管理用户的登录状态。通过setMaxInactiveInterval()设置会话超时,isNew()检查会话是否新建,以及getAttribute()和setAttribute()处理用户信息。在login.jsp中获取用户名,hello.jsp中设置用户名,而logout.jsp中通过调用invalidate()注销用户。内容涉及到Web开发中的会话管理策略。
725

被折叠的 条评论
为什么被折叠?



