Ch6. JSP built-in object--session object

Source: Internet
Author: User
Tags session id
Session Object

The session object is an instance of the Javax.servlet.http.HttpSession class. Has the same behavior as the session object in the Java servlets.

The session object is used to track sessions between individual client requests.


Main methods:



Each user is a different session, the server through the session ID to distinguish between different users, with

<%
	String id = session.getid ();
%>
View IDs
The cookie that is automatically set in the cookie is the user's session ID, so the session uses the Cookiede processing mechanism during the operation, and if the server restarts, the session ID is reassigned

If you want to keep it, use the serialization mechanism


Landing and cancellation

This is the most used place in the session.

The most common part of the session in all projects is login verification and logoff

Test, landing page (based on previous landing page improvements):

login.jsp

<%@ page ContentType = "text/html" pageencoding = "GBK"%> <%@ page import = "java.sql.*"%>  

welcome.jsp

<%@ page ContentType = "text/html" pageencoding = "GBK"%>

logout.jsp

<%@ page ContentType = "text/html" pageencoding = "GBK"%>

But this page is problematic, is "landing error" This information will always appear until you enter the correct information to jump. It will not be solved for the time being.

There are four techniques for session tracking:

Save through the form's hidden field through the session through the method provided by the session through address rewriting



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.