javaweb--jsp nine built-in objects and four scopes

9 built-in objects are included in the jsp script

这些对象都是servlet API的接口的实例,jsp对它们进行了初始化,可以在jsp页面中直接使用它们。

application : is an instance of servletContext, representing the web application to which the jsp page belongs, which can be used to store global variables and transmit information in jsp or servlet. It starts from the startup of the server until the shutdown of the server, during which time, this object will always exist
config : The config object represents the current JSP configuration information, but JSP pages usually do not need to be configured, so there is no configuration information. This object is rarely used in JSP pages, but is relatively more useful in servlets.
exception : An instance of java.lang.Throwable that represents exceptions or errors from other pages. Only works if the page is an error handling page.
out : Represents the output stream of the jsp page, which is used to output content to form html
page : Represents the page itself, which is not very useful.
pageContext: Provides access to all objects and namespaces in the JSP page, that is to say, he can access the SESSION where the page is located, and can also take an attribute value of the application where the page is located, which is equivalent to all the pages in the page. A master of functions.
requst : is an instance of the HttpServletRequest class, the client's request information is encapsulated in the request object, and the request is sent to the server through it, getAttribute(String name), getCharacterEncoding(), getParameter(String name) setAttribute(String key, Object obj)
response: is an instance of the HttpServletResponse class, getCharacterEncoding(), sendRedirect(java.lang.String location)
session : This object represents a session. A session begins when the client browser establishes a connection to the site. Close the browser and the session ends.
public String getId() Returns the unique ID number set by the JSP engine for the SESSION when it was created
void invalidate() Cancels the SESSION and makes the SESSION unavailable (commonly used)
String[] getValueNames() Returns an array containing all available properties in this SESSION ( commonly used)

Four scopes of jsp: page, request, session and application

page represents the current page, the corresponding built-in object is pageContext, and its valid scope is only in the current jsp page. You can use this variable from putting the variable in the pageContext to the end of the jsp page.
requst represents a request. If the variable is placed in the request, it means that its scope is the request, and its valid scope is the current request cycle. The so-called request cycle refers to the entire process from the initiation of the http request to the end of the server processing and the return of the response. In this process, you may use the forward method to jump to multiple jsp pages, and you can use this variable in these pages.
Session represents a session, and its valid scope is the current session. The so-called current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple request responses. In other words, as long as the user does not close the browser, the server has a way to know that these requests are initiated by a single person.
The application valid scope is the entire application. The whole application refers to the start of the application and the end of the application. We didn't say "from server startup to server shutdown" because a server may deploy multiple applications. Of course, if you shut down the server, all the above applications will be shut down. Variables in the application scope have the longest survival time, and they can always be used if they are not manually deleted. Unlike the above three, variables in the application can be shared by all users. If user A's operation modifies a variable in the application, user B will get the modified value when accessing

Guess you like

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