The four major scopes of Java are: 1. PageContext scope; 2. ServletRequest scope; 3. HttpSession scope; 4. ServletContext scope.
Java’s four major scopes are: PageContext, ServletRequest, HttpSession, and ServletContext. Please follow the editor to learn about the four major scopes of Java.
First calculate according to the scope:
is PageContext (jsp page)
If there are objects with the same name in different scopes, the system’s search order is page->request->session->application
application scope: The largest scope among all scopes. Since all servlets share a servletcontext object, all multiple servlets can share data between different servlets through servletcontext. It is a global variable
httpsession scope: The second largest scope, (session scope) when the request.getSession() method is called for the first time, the server will check whether there is already a corresponding session. If not, create a session in memory and return. When the session is not used for a short period of time (default 30 minutes), the server will destroy the session. If the server is shut down abnormally, unexpired sessions will also be destroyed. If you call the invalidate() method provided by the session, the session can be destroyed immediately.
servletRequest scope: The third largest scope, sharing data in the entire request chain. The longest time is used to hand over the processed data in the servlet to jsp for display. At this time, the parameters It can be placed in the servletRequest domain and brought over
PageContext scope: The smallest domain can obtain the other eight built-in objects. It can be considered as an entry object and can obtain all other domains. data in. It can jump to other resources. It provides forward and sendRedirect methods, which simplifies forwarding and redirection operations. It represents the page context. This object is mainly used to access shared data between jsps. It starts when a request to jsp is made. Destroyed at the end of the response
The above is the detailed content of What are the four major scopes of java?. For more information, please follow other related articles on the PHP Chinese website!