day78

Day78:

 The way the front page gets the value: request , application , session , Ajax

   Request : foreground:

  Stringname = request.get

 

 

Picture: put into session ,

The difference and connection between request, session, and application

blog.csdn.net April 12, 2012 at 09:35

request, session, application, comparison of the three

Scope ::

request < session < application

corresponding interface

The interface corresponding to the request object:

javax.servlet.ServletRequest 其子接口:javax.servlet.http.HttpServletRequest

The interface corresponding to the session object: javax.servlet.http.HttpSession

The interface corresponding to the application object: javax.servlet.ServletContext

Methods common to all three:

setAttribute(String name , Object o ) ,getAttribute(String name) ;

Simple analysis of the three:

1.request

Calling the above two methods only takes effect on one request (forwarding is not a request, because forwarding is the behavior of the server). When the information is returned to the client, the object is destroyed.

2.session

concept:

is server-side behavior

It is used to track the status of the client. When the user visits a site, the server will generate a sessionID for the client and return it to the client in the form of a cookie. When the client visits other services of the site, it will bring The user sends a request together with the current sessionID, and has identified which user it is. A user is like a session object, which does not interfere with each other.

Operating mechanism:

 

Session failure reasons:

1) Session expired

2) The server calls invalidate() to make it invalid

3) Most of the current web pages support session. To make the page lose session function,

Then add <%@ page session="false" %> to the page, but it is generally not done

Session important methods:

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

2) isNew() --- determine whether the session is new

3) invalidate() --- invalidate the current session and release resources

4) setMaxInactiveInterval(int interval) --- Set the time interval (in seconds) that the session is inactive,

After this time, the session is invalid.

If it is set to a negative number, or 0, the time interval of session inactivity is not limited. The default is generally 30 minutes.

5) setAttribute(String name , Object o ) ,getAttribute(String name)

Application scenarios:

1) Login

2) shopping cart

3.application

Call the above two methods, one server has one application object, users share one application, and the application is destroyed when the server stops, (for the number of website visits)

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325732813&siteId=291194637