Advertisement
Methods | Description |
---|---|
void setAttribute(String name, Object value) | This method sets an object with a name in a session. |
Object getAttribute(String name | This method gets an object stored in a session with a name, or null. |
void removeAttribute(String name) | This method removes an object with a name from the session. |
long getLastAccessedTime() | This method returns the last time(since midnight Jan 1, 1970 in milliseconds) since a client accessed this session. |
int getMaxInactiveInterval() | This method gets the time(in seconds) before servlet contained invalidates the session. |
void setMaxInactiveInterval(int seconds | This method sets the time between client requests before the servlet container invalidates the session. |
long getCreationTime() | This method gets the creation time of the current session, since 1970 in milliseconds. |
ServletContext getServletContext() | This method returns the ServletContext to the current session. |
boolean isNew() | This method gives a true if the current session is new and client doesn't know about it. |
<html>
<head>
<title>Creating a Session</title>
</head>
<%@page import="java.util.Date" session="true"%>
Information about the newly created session by this JSP web page - <br/>
Is Session new : <%= session.isNew() %>
Session ID: <%= session.getId()%> <br/>
Session creation time: <%= new Date(session.getCreationTime())%> <br/>
Last Accessed Time of Session : <%= session.getLastAccessedTime()%> milliseconds since Jan 1, 1970. <br/>
Maximum inactive interval : <%= session.getMaxInactiveInterval()%> seconds
</body>
<html>
Advertisement
<html>
<head>
<title>Creating a Session</title>
</head>
<%@page import="java.util.Date" session="false"%>
<body>
No session will be created after setting session attribute to false in page directive.
Hence, accessing the session object will result in an error.
Session ID: <%= session.getId() %> <br/>
Session creating time : <%= new Date(session.getCreationTime()) %> <br/>
</body>
<html>
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement