1. hidden objects in JSP
Because JSP is an embedded language, some necessary parameters, such as the request object and response object, cannot be explicitly passed in, therefore, the JSP specification provides several implicit objects to implement the Discount Function. The so-called implicit object means that you agree to use a name to refer to a specific object, and you can use it without explicit declarations when writing JSP, the JSP Engine is responsible for adding the implicit object to the explanation. java file. Common implicit objects include application, session, request, response, out, page, exception, and pagecontext.
1. Session Object
2. Application Object
3. Request object
4. respose object
5. Out object
6. Page Object
7. Exception object
8. pagecontext object
1. Session Object
As mentioned earlier in the servlet section, when a customer first accesses a webpage file under the Web server publishing directory (one or more web servers have one or more "publishing directories, the Web server automatically creates a session object and assigns it a unique ID number. You can save the required information to this session object for use as needed. A session object is an object obtained through the getsession method. It is an implicit object in JSP. For more information about the use of session objects, see servlet API
2. Application Object
When the Web server starts, the web server automatically creates an application object. Once an application object is created, it will exist until the Web server is closed. Therefore, the application object can be used to share data among multiple customers.
A Web Server often has multiple release directories. When the Web server starts, it automatically creates an application object for each release directory. These application objects are independent of each other, and one-to-one correspondence with the release directory.
Application lifecycle: starts from the Web server and closes the web server.
Scope of application in the life cycle: You can operate the application object "corresponding to release directory a" in all webpage files under the same release directory, in addition, all the customers accessing publishing directory a share an application object. Therefore, when data information is stored in the application, all the customers who access this publication Category A can access it, achieving data sharing among multiple customers.
The base class of the Application object is: javax. servlet. servletcontext class. You can use the getservletcontext () method in this class to obtain the application. For more information, see servlet API.
3. Request object
The request object is mainly used to obtain the data information submitted by the customer in the form and transfer the data information between multiple webpages. You can also obtain the Web server parameters. It corresponds to the request object in the servlet parameter.
The base class of the request object is javax. servlet. servletrequest.
If the transmission protocol is HTTP, It is javax. servlet. httpservletrequest.
For more information, see servlet API.
4. respose object
The respose object is mainly used to output information to the client and respond to client requests. It corresponds to the response object in the servlet parameter.
The base class of the respose object is javax. servlet. servletresponse.
If the transmission protocol is HTTP. It is javax. servlet. httpservletresponse.
For more information, see servlet API.
5. Out object
The out object is used to output data to the client.
The base class of the out object is the javax. servlet. jspwriter class, which is slightly different from the printwriter obtained by httpservletresponse In the servlet.
Writer is inherited, so it is basically the same.
For more information, see servlet API.
6. Page Object
The page object is an instance of the current JSP page. Its type is Java. Lang. object.
The method is the method in the object class. For example, class getclass () returns the expression of the class corresponding to an object at runtime, so as to get the corresponding information. String tostring () returns the string representation of the current object. The page object can be replaced by this on the current page.
For more information, see Java 2 API.
7. Exception object
When exceptions or errors occur during execution of JSP pages, an exception object is automatically generated.
After setting the settings on the current page, you can use this exception object to find page error information.
The exception object type is: Java. Lang. exception class.
Common Methods for exception objects are:
String getmessage ()
Returns Error information on the page. If no error message is displayed, null is returned.
Void printstacktrace ()
Prints and displays the current exception object and its execution track in the form of a standard error output stream.
For more information, see Java 2 API.
8. pagecontext object
The pagecontext object is equivalent to the container of the current page and can access all objects on the current page.
The base class of the pagecontext object is the javax. servlet. jsp. pagecontext class.
Common Methods for pagecontext objects:
Httpsession getsession () gets the session object of the current page.
Servletrequest getrequest () gets the request object of the current page.
Servletresponse getresponse () gets the response object of the current page.
Servletcontext getservletcontext () gets the Application Object of the current page.
Servletconfig getservletconfig () gets the config object of the current page.
Object getpage () gets the Page Object of the current page.
Jspwriter getout () gets the out object of the current page.
Exception getexception () gets the exception object of the current page.
Void setattribute (string variabelname, object objectname)
Save the object objectname to pagecontext.
Object getattribute (string variablename)
Obtain the data stored in the pagecontext object. If the variablename parameter does not exist in the current session, null is returned.
Void removeattribute (string variablename)
Delete the object named variablename in pagecontext. If the object name does not exist, no operation is performed.
For more information, see servlet API.
Source of the above original article:
Http://blog.chinaunix.net/u/4764/showart.php? Id = 136125