Moon. Maintain state with session--based on Java Web Advanced Programming Chapter 5th using session Maintenance State

Source: Internet
Author: User

5.1 Questions raised

How do I correlate multiple requests from a customer?

5.1.1 Maintenance Status

A session is used to maintain the state between requests and requests. HTTP is stateless

From the server perspective, when a user's Web browser opens the first socket that is linked to the server, the request begins until the server returns the last packet and closes the connection.

At this point, there is no connection between the browser and the server, and the next request link will not be associated with the previous request.

In your shopping cart, each time you add items to your shopping cart, how do you know that they are all from the same browser in the same base collection, and that they are associated to your browser and that others are

Unable to view your shopping cart

5.1.2 Remembering Users

When you log in to the online forum, users will have their own user name and password, and the user will need to provide a user name and password for personal authentication (using the user name and password identification method has always been controversial

The 25th chapter discusses), after login user reply theme, add Forum theme, participate in other user's private routines you, report to moderator topic or reply, also can collect subject, notice the whole process user just log in

Once, the system needs to remember the user in some way, and the session provides the functionality

5.1.3 Starting the application workflow

It is common for users to use some form of workflow when they are using an advanced Web application to complete a task.

A workflow contains many steps, and the end of each step represents the end of a single task. Combining all the steps together makes up the entire workflow.

For example, when you create a news site for publishing, a journalist may first enter a page that can enter a title, a slogan, and a text, and format the elements.

On the next page it may be necessary to select one or more photos related to the article and specify how to display them.

It also needs to select similar articles or keywords that can be used to search for similar articles so that they are listed in the relevant article box

5.2 Using sessions session cookie and URL rewriting

1. Theoretical basics of conversation and how to implement sessions

Specification for session implementations in 2.java EE Web applications

Session: Some file, memory fragment, object, or container managed by a server or Web application that contains various different data assigned to it. The data can be: User name, shopping cart,

Workflow details, and so on. There is no need to maintain or maintain any such data in the user's browser.

A session between the server and the browser is usually given a randomly generated string called the session ID.

When the session is first created (that is, when the request is received), the session ID that is created is returned to the user's browser as the first part of the response.

The browser's request will then include the session ID in some way,

When the application receives a request that contains a session ID, he can associate an existing session with the current request with that ID.

The next discussion is how to return the session ID from the server to the browser and include the ID in the subsequent request

Currently, two techniques can be used to accomplish this task: Session cookies and URL rewriting

5.2.1 Understanding Session Cookies

Moon. Maintain state with session--based on Java Web Advanced Programming Chapter 5th using session Maintenance State

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.