Request,session,application, three comparisons

Source: Internet
Author: User

Scope::

Request < Session < application

Each corresponding interface

The interface that corresponds to the request object:

Javax.servlet.ServletRequest its sub-interface:javax.servlet.http.HttpServletRequest

Interface for session object:javax.servlet.http.HttpSession

Interface for application objects:javax.servlet.ServletContext

Three common methods:

SetAttribute (string name, Object o), getattribute (string name);

Simple analysis of three people:

1.request

Call the above two methods, only on a single request (forwarding not count the request, because the forwarding is the server-side behavior) in effect, when the information returned to the client, the object is destroyed

2.session

Concept:

is the server-side behavior

Used to track the status of the customer, when the user to visit a site, the server will generate a SessionID for the customer, in a cookie way to return to the client, when the customer to visit the site's other services, will bring the current SessionID Together to make a request, has identified which user, a user is like a Session object, do not interfere.

Operating mechanism:


Session Failure Reason:

1) Session expires

2) server-side call invalidate () to invalidate it

3) Now the majority of the page is to support the session, to let the page lose the session effect,

Add <%@ page session= "false" to%>, but this is not normally done

Important methods of Session:

1) getId ()---Get the ID number of the session, each ID number is different

2) isnew ()---Judge if the session is new

3) Invalidate ()---Let the current session expire and release resources

4) setmaxinactiveinterval (int interval)---Set the time interval (in seconds) at which the session is inactive.

Over that time, the session expires,

If you set a negative number, or 0, you do not limit the session inactivity interval, which is typically 30 minutes by default

5) SetAttribute (string name, Object o), getattribute (string name)

Application Scenarios:

1) Login

2) Shopping Cart

3.application

call the above two methods , a server on a Application object, the user shared a application, when the server stopped application was destroyed, (for site visits)

----------------------------------------------

Transfer from http://blog.csdn.net/hzc543806053/article/details/7416007

Request,session,application, three comparisons

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.