9 large built-in objects for JSPs

Source: Internet
Author: User
Tags map class throwable

1. Overview

JSP of these 9 built-in objects, are Servlet API instances, that is, within the JSP page, can be directly used;

PS: By the way JSP 4 wide range:

JSP four kinds of scopes, respectively page, request, session, application.

Application:
The global scope, the entire application share, is the same webapp share in the deployment file, with a lifecycle of: application start to stop.

Session:
Session scope, when the user first accesses a new session, the server can remember the session state. Life cycle: Session timeout, or server-side forcing session to expire.

Request:
The request scope is a request from the client.

Page:
A JSP page.

The 9 large built-in objects in the JSP are:

Request object Type Javax.servlet.ServletRequest Scope request
Response Response Object Type Javax.servlet.SrvletResponse scope Page
PageContext page Context object type Javax.servlet.jsp.PageContext Scope page
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 object Type Javax.lang.Object Scope page
Exception exception Object type javax.lang.Throwable Scope page

Request

The Request object is an object of type Javax.servlet.httpServletRequest. This object represents the client's request information and is primarily used to accept data that is delivered to the server over the HTTP protocol. (including header information, System Information, request method, request parameters, etc.). The request object has a scope of one-time requests;

Response

Response represents the response to the client, primarily the object that the JSP container has processed back to the client. The response object also has a scope, which is only a valid Javax.servlet.ServletResponse subtype within the JSP page that encapsulates the output returned to the HTTP client and sets the response header and status code to the page

The way. Often used to set HTTP headers, add cookies, set the type and status of response content, send HTTP redirects, and encode URLs. A scope is page (page execution period).

PageContext

Javax.servlet.jsp.PageContext (abstract Class) type, scoped to page (pages execution period).

This object provides the ability to query and modify properties of all four scope hierarchies, and it is also used to forward requests to other resources and methods that contain other resources;

Session

Javax.servlet.http.HttpSession type, scope session.

Mainly used to track conversations, if you do not need to track the session object between requests, you can specify session= "false" in the page directive, you need to remember that the PageContext object can also be associated with Session.getattribute (), Session.setattribute () Gets and sets the session properties in the same way.

The Session object is an object that is automatically created by the server that is related to the user request. The server generates a Session object for each user that holds the user's information and tracks the user's operational status. The session object uses the map class internally to hold the data, so the format of the saved data is "Key/value". The value of the Session object

You can make complex object types, not just string types.

Application

The Javax.servlet.ServletContext type, scoped to application (the entire program run).

The servlet environment is obtained by calling the Getservletconfig (). GetContext () method. It provides information about the server version, application-level initialization parameters and absolute path of in-app resources;

The Application object saves information in the server until the server shuts down, otherwise the information saved in the Application object will be valid throughout the application. The Application object has a longer life cycle than the session object, similar to the system's global variables. Object is a hard-to-save variable used in a Java Web application.

These variables are accessible to all users, regardless of when they are used. The biggest feature of application objects is that there is no so-called life cycle. The life cycle refers to whether the client's browser is closed and the Application object exists on the host. The Application object is not invalidated until the server shuts down.

Out

The Javax.servlet.jsp.JspWriter type that represents the output stream object. A scope is page (page execution period).

The Out object represents the object that sends the data to the client, and unlike the "Response" object, the content sent through the "out" object is the content that the browser needs to display, the text level, which can be written directly to the client by the "Out" object, which is dynamically generated by the program. HTML file. In addition to Pirnt and println, common methods include

Clear,Clearbuffer,Flush,getbuffersize, and getremaining, because a buffer is contained inside the "Out" object, Therefore, some methods to operate the buffer are needed;

Config

Javax.servlet.ServletConfig, the scope is page (pages execution period);

The main purpose of the Config object is to obtain the server configuration information. When a servlet initializes, the container passes some information through the Config object to the servlet. Developers can initialize parameters for servlet programs and JSP pages in the application environment in the Web. xml file.

Page

A Page object represents the JSP page itself, just a synonym for this reference. It is generally inaccessible to JSP page creators, so it is seldom used for this object. The "Page" object represents a running class object produced by a JSP file and is not recommended for general audiences.

exception

Exception:java.lang.Throwable, a catch block in the JSP error page has been benefited but not captured;

The exception object represents the exception object that is generated by the JSP file runtime, which cannot be used directly in a generic JSP file, but only in a JSP file that uses the "<%@ page iserrorpage=" true "%>";

To use the exception object, the iserrorpage of the page must indicate true. using the Try/catch keyword in Java to handle exception cases, if there is no caught exception in the JSP page, the exception object is generated and the exception object is routed to the error page set in the page directive, and then in the wrong

Processing the corresponding exception object in a false-display page

View each object specific method can be viewed: http://baike.baidu.com/view/1690487.htm

9 large built-in objects for JSPs

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.