Three scope objects of servlet

One, request

Save the object: setAttribute()
Get the object: getAttribute()
Delete the object: removeAttribute()

The data saved by the request is only valid in the current request. If you save the data in the request, it can only be obtained in the current request. Other requests cannot be obtained. It is generally used to obtain data from the server.

二、session

Save the object: setAttribute()
Get the object: getAttribute()
Delete the object: removeAttribute()

The data saved by the session is valid in the current session. The current session refers to the interactive operation that the browser has not closed. If the browser is closed and then opened, it is another session. For example, the login status can be realized. If you close the browser, you need to log in again.

三、ServletContext

Save the object: setAttribute()
Get the object: getAttribute()
Delete the object: removeAttribute()

It can be accessed from all servlets in the project. As long as the server is not shut down, the data will always exist.

Guess you like

Origin blog.csdn.net/qq_41504815/article/details/114940421