A total of 9 such objects are predefined in JSP, namely: request, response, session, application, out, pagecontext, config, page, exception
1. Request object
The request object represents the client's request information and is mainly used to accept data transmitted to the server through the HTTP protocol. (Including header information, system information, request method and request parameters, etc.).
The scope of the request object is a request.
String s = ("xxxx");//Receive value("key","value");//Cross out("key");//according tokeyValue Received
2. Response object
The response represents a response to the client, mainly passing objects processed by the JSP container back to the client. The response object also has scope, and it is only valid within the JSP page.
("url");//Jump().append("xxxxx");//Enter content to the page
3. Session object
Mainly used to save each user information separately and associate the session with the request
The session is saved on the server. It is a state saving process in each session. By default it is a 30-minute life span.
//Create sessionHttpSession session=(); //Write session("key","value"); //Read session("key");
4. Application object
The application object can save information on the server until the server is closed, otherwise the information saved in the application object will be valid throughout the application. Compared with the session object, the application object has a longer life cycle, similar to the system's "global variables".
This Application object is generated after the server is started. When the client browses between various pages of the website visited by the website, the Application object is the same until the server is closed. However, when different from the Session object, all customers' Application objects are the same, that is, all customers share this built-in Application object.
setAttribute(String key,Object obj): Add the object obj specified by the parameter Object to the Application object, and specify an index keyword for the added object.
getAttribute(String key): Gets the object containing keywords in the Application object.
5. Out object
The out object is used to output information within a web browser and to manage the output buffer on the application server. When using the out object to output data, you can operate on the data buffer to clear the residual data in the buffer in time and give out the buffer space for other outputs. After the data output is completed, the output stream must be closed in time.
An output stream when Out object is used to output data to the client. Out object is used for output of various data. The commonly used methods are as follows.
(): Output various types of data.
(): Output a newline character.
(): Close the flow.
6. pageContext object
The function of the pageContext object is to obtain any scope parameters, through which you can get out, request, response, session, application and other objects of the JSP page.
The creation and initialization of the pageContext object are done by the container. The pageContext object can be used directly in the JSP page.
The page object represents the JSP itself and is only legal within the JSP page. The page implicit object essentially contains variables referenced by the current Servlet interface, similar to this pointer in Java programming.
7. config object
The main function of the config object is to obtain the configuration information of the server. A config object can be obtained through the getServletConfig() method of the pageConext object. When a servlet is initialized, the container passes certain information to the servlet through the config object. Developers can provide initialization parameters for Servlet programs and JSP pages in the application environment in the file.
8 cookie objects
A cookie is a piece of text saved by a web server on the user's hard disk. Cookies allow a web site to save information on the user's computer and then retrieve it. For example, a web site may generate a unique ID for each visitor and then save it on each user's machine as a cookie file.
It is divided into temporary cookies and long-term cookies. The temporary cookie browser will be closed and it will be closed. Long-term cookies are placed on the hard drive and will be lost when they expire.
//Write cookiesCookie c = new Cookie("key","value"); (c); //Read cookiesCookie[] cc = (); for(Cookie c:cc){ }
Cookie objects are used to count the number of visitors to the website when they are typical of the application. Due to the use of proxy servers, caches, etc., the only way to help the website accurately count the number of visitors is to establish a unique ID for each visitor. Using cookies, the website can do the following:
Determine how many people have visited. Determine how many visitors are new users (i.e., first visit) and how many old users are.
Determine how often a user visits the website. When a user first visits, the website creates a new ID in the database and transmits the ID to the user through a cookie. When the user visits again, the website increases the counter corresponding to the user ID by 1 to get the number of visits from the user.
9. Exception object
The function of the exception object is to display exception information. It can only be used in a page containing isErrorPage="true". Using this object in a general JSP page will not be able to compile the JSP file.
Like all Java objects, exception objects have an inheritance structure provided by the system.
The exception object defines almost all exceptions. In Java programs, you can use the try/catch keyword to handle exceptions; if an exception that is not caught appears in the JSP page, an exception object will be generated, and the exception object will be transferred to the error page set in the page directive, and then the corresponding exception object will be processed in the error page.
The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!