Built-in object features:
1. Provided by the JSP specification, without being instantiated by the creator.
2. Implementing and managing through the Web container
3. All JSP pages can be used
4. Available only in expressions or snippets of script elements (<%= using built-in object%> or <% using built-in objects%>)
Common built-in objects:
1. Output input object: Request object, Response object, out object
2. Communication Control object: PageContext object, Session object, Application object
3. Servlet object: Page object, config object
4. Error Handling object: Exception object
Request (Javax.servlet.ServletRequest) It contains information about browser requests. This object allows you to obtain header information, cookies, and request parameters in the request.
Response (Javax.servlet.ServletResponse) is stored in the object as a result of the JSP page processing results returned to the user. and provides methods for setting response content, response headers, and redirection (such as cookies, header information, etc.)
Out (Javax.servlet.jsp.JspWriter) is used to write content to the output stream of a JSP page instance, providing several methods that you can use to echo the output to the browser.
PageContext (Javax.servlet.jsp.PageContext) describes the running environment for the current JSP page. You can return access to other implicit objects of a JSP page and its properties, and it also implements the method of transferring control from the current page to another page.
Session (Javax.servlet.http.HttpSession) sessions object stores information about this session, or you can assign properties to a session, each with a name and value. Session objects are primarily used to store and retrieve property values.
Application (Javax.servle.ServletContext) stores the servlet that runs the JSP page and the contextual information for any Web components in the same application.
Page (Java.lang.Object) represents the servlet instance of the current JSP page
Config (Javax.servlet.ServletConfig) This object is used to access the initialization parameters of the servlet instance.
Exception (Javax.lang.Throwable), when an exception is thrown on a page, is forwarded to the JSP error page, which is provided to handle errors in the JSP. You can use <% @page iserrorpage= "true" only on the error page%>
JSP built-in objects |
Function |
Main methods |
Out |
outputting data to the client |
Print () println () flush () Clear () Isautoflush () GetBufferSize () Close () ..... |
Request |
Requesting data from a client |
Getattributenames () getcookies () getparameter () getparametervalues () SetAttribute () Getservletpath () ..... |
Response |
Encapsulates the response generated by the JSP and is then sent to the client in response to the customer's request |
Addcookie () Sendredirect () setContentType () Flushbuffer () getbuffersize () Getoutputstream () Senderror () Containsheader () ..... ..... |
Application |
|
|
Config |
Represents the configuration of a servlet, and when a servlet initializes, the container passes some information through this object to the servlet |
Getservletcontext () Getservletname () Getinitparameter () Getinitparameternames () () ..... |
Page |
An instance of the JSP implementation class, which is the JSP itself, through which it can be accessed |
Flush () ..... |
PageContext |
Wraps the context of the page for the JSP page. Manages the question of a named object that belongs to a particular visible part of the JSP |
Forward () getattribute () getexception () getrequest () GetResponse () Getservletconfig () GetSession () Getservletcontext () SetAttribute () RemoveAttribute () Findattribute () ..... ..... |
Session |
Used to save each user's information in order to track each user's action status |
GetAttribute () getId () Getattributenames () Getcreatetime () Getmaxinactiveinterval () Invalidate () IsNew () |
exception |
To reflect a running exception |
GetMessage () ...... |
PageContext, request, session, application four scopes
1, if the variable is placed in the PageContext, it means that its scope is page, its valid range is only in the current JSP page. You can use this variable from the start of placing the variable in PageContext to the end of the JSP page.
2, if the variable is placed in the request, it indicates that its scope is request, its valid range is the current request period. The so-called request period, that is, from the HTTP request initiation, to the end of the server processing, return the entire process of response. You may use forward to jump through multiple JSP pages in this process, and you can use this variable in these pages. 3, if the variable is placed in the session, it indicates that its scope is the session, its effective range is the current session. The so-called current session refers to the process of opening the browser from the user to the user closing 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 person, the entire process is called a session, and the variables placed in the session,
4, if the variable is placed in the application, it means that its scope is application, its effective range is the entire application. The entire application is launched from the app to the end of the app. We did not say "boot from server to server shutdown" is because a server may deploy multiple applications, of course you shut down the server, will be all the above applications are closed. Application The variables in the scope, they survive the longest, and if not manually deleted, they can be used all the time. Unlike the three above, the variables in the application can be shared by all users. If user A's operation modifies the variable in application, the User B gets the modified value when he accesses it. This will not happen in any other scope, page, request, session is completely isolated, regardless of modification will not affect the other
Four scopes of JSP and nine large objects