I. Introduction of the SESSION
The main function of the Sessiond object is to complete the user's logon, logoff and other operations, each session object represents a different access user. The session object is an instantiated object of the Javax.servlet.http.HttpSession interface. The common methods are:
no
3
description |
1
public String getid () |
get ID |
2
public long GetCreationTime () |
Get creation time |
get last operation time |
4
public Boolean isnew () |
determine if new user |
5
public void invalidate () |
let session expire |
6 |
Public enumeration Getattributenames () |
Get all property names |
Second, get the session Id
<%@ pagecontenttype= "text/html" pageencoding= "GBK"%>
Third, login and cancellation (important)
1. Login and logout
LOGIN.JSP:
Complete the display of the login form and submit data to this form. If the login succeeds, the property is saved, and if it fails, the logon failure message is displayed.
WELCOME.JSP:
After the user login successfully can display information, if not logged in, you want to give a message not logged in, at the same time give the login connection address.
LOGOUT.JSP:
Complete login logout, log off after the page jumps back to the login.jsp page.
Example Login System sample
LOGIN.JSP:
<%@ page contenttype= "text/html" pageencoding= "GBK"%>WELCOME.JSP:
<%@ page contenttype= "text/html" pageencoding= "GBK"%>
LOGOUT.JSP:
<%@ page contenttype= "text/html" pageencoding= "GBK"%>
2. Get user operation time
<%@ page contenttype= "text/html" pageencoding= "GBK"%>
The above content reference Javaweb development actual combat Classics (teacher pulpit)
This article is from the "Beyond the Horizon" blog, be sure to keep this source http://udbful.blog.51cto.com/10601869/1683384
02_06 JSP built-in object session