Nine built-in JSP objects

Source: Internet
Author: User

Built-in object (also known as implicit object, with nine built-in objects): You can use it in script code and expressions without pre-declaration.

1-out:

Javax. servlet. jsp. JspWriter type, representing the object of the output stream. Scope: page (page execution period)

Request: subtype of javax. servlet. ServletRequest. This object encapsulates the HTTP

Request details (parameters, attributes, headers, and data ). The scope is request (user request period ).
You can view the API

Response: The subtype of javax. servlet. ServletResponse. This object encapsulates the output returned to the HTTP client and sends it to the page

The author provides a method to set the response header and status code. It is often used to set HTTP headers, add cookies, and set the types and formats of response content.

Sends HTTP redirection and encoded URLs. The scope is page (page execution period ).


PageContext: javax. servlet. jsp. PageContext (abstract class) type, scope is page (page execution period ). This object

Provides the ability to query and modify attributes at all four scopes. It also provides methods to forward requests to other resources and include other resources.

:
All methods of this object are abstract methods.

Session: javax. servlet. http. HttpSession type. It is mainly used to track conversations. Scope session (session Period -).

HttpSession is an object related to a single WEB browser session similar to a hash table. It exists between HTTP requests and can be stored as any

The type of the named object.
If you do not need to track session objects between requests, you can specify session = "false" in the page command"
Remember that the pageContext object can be retrieved in the same way as session. getAttribute () and session. setAttribute ().

And set session properties.

Application: javax. servlet. ServletContext type. The servlet environment calls getServletConfig

(). GetContext () method. The scope is application (throughout the program running ). It provides the server version and Application

LEVEL initialization parameters and absolute path of resources in the application, registration information method


Config: javax. servlet. ServletConfig, with the scope of page (page execution period)

Exception: java. lang. Throwable, which has been obtained but not captured by a catch block on the JSP error page

Any instance of java. lang. Throwable transmits to the URI of errorPage. The scope is page (page execution period ). Note:

Exception is valid only when the page command has the attribute isErrorPage = "true.

Page: java. lang. Object type, pointing to the page itself. The scope is page (page execution period

The nine built-in objects in JSP are:
Request Request object type javax. servlet. ServletRequest scope request
Response object type javax. servlet. SrvletResponse scope Page
PageContext Page Context object type javax. servlet. jsp. PageContext scope Page
Session Session object type javax. servlet. http. HttpSession scope session
Application Application Object Type javax. servlet. ServletContext Scope application
Out output object type javax. servlet. jsp. JspWriter scope Page
Config configuration object type javax. servlet. ServletConfig scope Page
Page Page Object Type javax. lang. Object scope page
Exception object type javax. lang. Throwable scope page

The request object represents a request from the client, such as the information we fill in the FORM. It is the most common object.

Common methods include getParameter, getParameterNames, and getParameterValues. These methods are called to obtain the values of parameters contained in the request object.

The response object represents the response to the client, that is, the data sent to the client can be organized through the response object. However, because the organization mode is relatively low-level, it is not recommended for common readers to use it directly when sending text to the client.

The pageContext object can be called a page context object during literal translation, which indicates the running properties of the current page.

Common methods include findAttribute, getAttribute, getattributessscope, and getAttributeNamesInScope.
In general, not many pageContext objects are used. Page properties are used for processing only when the project is complex.

The session object represents the session established between the server and the client. It is used when customer information needs to be retained on different JSP pages, such as online shopping and customer Track Tracking. The "session" object is based on the cookie. Therefore, you should check whether the client has enabled the cookie. Common methods include getId, getValue, getValueNames, and putValue.

Summary
HTTP is a stateless protocol;
The Web Server has no historical memory for each client request;
Session is used to save client status information;
Written by the Web Server;
Stored on the client;
Each client access passes the last session record to the Web Server;
The Web Server reads the session submitted by the client to obtain the client's status information.

The application Object provides global information about the application running on the server. Common methods include getMimeType and getRealPath.

The out object represents the object that sends data to the client. Unlike the "response" object, the content sent through the "out" object is the content that the browser needs to display, which is text-level, you can use the "out" object to directly write an HTML file dynamically generated by the program to the client. In addition to pirnt and println, common methods include clear, clearBuffer, flush, getBufferSize, and getRemaining. This is because the "out" object contains a buffer, therefore, some operations on the buffer zone are required.

The "config" Object provides some configuration information. Common methods include getInitParameter and getInitParameterNames to obtain the parameters during Servlet initialization.

The "page" object represents a running class object generated by JSP files. It is not recommended for general readers.

The "exception" object represents the exception object generated when the JSP file is running. This object cannot be directly used in common JSP files, instead, it can only be used in JSP files that use "<% @ page isErrorPage =" true "%>"


From the column gdn_wolf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.