Introduction:
Output :
1. session object is an instance of class javax.servlet.http.HttpSession.
2. The session object is used to store and retrieve client information across the multiple requests. The session object is not available if the session="false" is used in page directive.
3. The previous two objects, request and response, are used to pass information from web browser to server and from server to web browser respectively. The Session Object provides the connection or association between the client and the server.
Methods:
1.getCreationTime | This method is used to return the session created time |
2. getLastAccessedTime | The getLastAccessedTime method of session object is used to return the latest time of the client request associated with the session. |
3.getId | The getID method of session object is used to return the unique identifier associated with the session. |
4.invalidate() | invalidate method of session object is used to discard the session and releases any objects stored as attributes. |
5.getMaxInactiveInterval | The getMaxInactiveInterval method of session object is used to return the maximum amount of time the JRun keeps the session open between client accesses. |
6.setMaxInactiveInterval() | This is another setMaxInactiveInterval() method that a developer can use to set the timeout explicitly for each session. |
7.removeAttribute(String name) | The removeAttribute method of session object is used to remove the attribute and value from the session. |
8.setAttribute(String, object) | The setAttribute method of session object is used to set the object to the named attribute. |
Example: test.jsp
<%@ page session="true" %> <% session.setMaxInactiveInterval(600); session.setAttribute("SITE", "MYJAVAHUB.COM"); %> <table border= 2> <% out.println("<tr><td>Created Time of Session is: </td><td>" + session.getCreationTime()+"</td></tr>"); out.println("<tr><td>Last Accessed Time of Session is:</td><td> " + session.getLastAccessedTime()+"</td></tr>"); out.println("<tr><td>The Session ID is: </td><td>" + session.getId()+"</td></tr>"); out.println("<tr><td>Maximum Inactive Interval of Session in Seconds is : </td><td>"+session.getMaxInactiveInterval()+"</td></tr>"); out.println("<tr><td>SITE </td><td>" + session.getAttribute("SITE")+"</td></tr>"); %> </table> |
Output :
No comments:
Post a Comment