JSP There are nine large built-in objects:
(1) HttpSessionClass ofSessionObject
function: Mainly used to save each user information separately, the session associated with the request;
Session state Maintenance isWebthe problem that the application developer must face.
(2) HttpServletRequestClass ofRequestObject
function: Represents the Request object, which is used primarily to accept clients throughHTTPthe Protocol connection transmits data to the server side.
(3) HttpServletResponseClass ofResponeObject
function: Represents the response object, primarily used to send data to the client
(4) JspWriterClass of outObject
function: Mainly used to output data to the client;
Outthe base class isJspWriter
(5) ServletcontexClass ofApplicationObject
role: Mainly used to save user information, code snippets of the operating environment;
It is a shared built-in object, where multiple users in a container share aApplicationobject, so its saved information is shared by all users.
(6) PageContextClass ofPageContextObject
Role: Manage page Properties,to beJsppage Wraps the context of the page, managing theJspThe access to the named object in the specially visible part of the, and its creation and initialization are done by the container.
(7) ServletConfigClass ofConfigObject
function: A code fragment configuration object that representsthe configuration of the Servlet.
(8) The page(equivalent this) object of the object class
Role: Handling JSP Web page, An instance of the Object class, refers to an instance of a JSP implementation class, that is, It is also the JSP itself, only in within the JSP page range is legal.
(9) Exception
Role: Handling Errors and exceptions that occur when JSP files are executed
There are 11 large built-in objects in El:
A JSP developer can use an El implicit object in an El expression without any explicit code-alive declaration. Implicit objects are designed to provide a convenient way for JSP programming, through the implicit object, code written in El can directly use the JSP page of some of the most commonly used places. There are a total of 11 implicit objects, and these 11 implicit objects can be divided into 5 main categories:
*jsp an implicit object.
* Scope accesses an implicit object.
* parameter accesses an implicit object.
* The first access to an implicit object.
* Initialize parameters to access an implicit object.
There is only one El implicit object in the jsp implicit object class, which is the PageContext implicit object. This is actually the same object as the JSP implicit object with the same name. The remaining El implicit objects are Java Mappings (map), and they simply provide an easier way to access some of the properties of the PageContext implicit object.
There are 4 scope implicit objects, Pagescope, Requestscope, Sessionscope, and Applicationscope, respectively. These implicit objects are mappings that make it easy to access scope properties. For example, the Username property attached to the request scope can be accessed directly through the EL expression ${requestscope.username}.
There are two parameters to access an implicit object, which can be used to access HTTP request parameters (form submission parameters), param and paramvalues. Param is a mapping for accessing single-valued parameters, and paramvalues can be used to access parameters that may contain multiple values. The next experiment will show how this will be handled.
There are 3 first access implicit objects that can be used to access HTTP headers, respectively, header, Headervalues, and Cookie. These mappings are useful if you want to access HTTP headers or cookies in the original way.
There is also an initialization parameter that accesses an implicit object: Initparm. This mapping can be used to access the values of the initialization parameters, which are typically set in Web. Xml.
| Category |
Identifier |
Describe |
| Jsp |
PageContext |
PageContext instances correspond to the processing of the current page |
| Scope |
Pagescope |
Map class associated with the name and value of the page scope property |
| Requestscope |
Map class associated with the name and value of the request scope property |
| Sessionscope |
The Map class associated with the name and value of the session scope property |
| Applicationscope |
Map class associated with the name and value of the application scope property |
| Request parameters |
Param |
Map class that stores the primary values of request parameters by name |
| Paramvalues |
A Map class that stores all the values of a request parameter as a String array |
| Request Header |
Header |
Map class for storing request header primary values by name |
| Headervalues |
The Map class that stores all the value of the request header as a String array |
| Cookies |
Cookies |
Map class that stores the cookie that is included with the request by name |
| Initialize parameters |
Initparam |
Map class for storing WEB application context initialization parameters by name |
In fact, my main purpose is to clarify the PageContext object, as follows:
The role of PageContext in JSP PageContext The implied object corresponds to the object of the Javax.servlet.jsp.PageContext type, and the implied object is automatically added to the PageContext, which allows you to obtain a Servlet object corresponding to the implied object associated with the JSP, such as a getrequest () can get ServletRequest, getservletconfig () can get Servletconfig,getsession () can get httpsession and so on. Providing a Servlet object corresponding to the implied object is not the main function of PageContext, its main functions are to provide a single interface to manage various public objects (such as HttpSession, ServletContext, ServletConfig , ServletRequest, Servletresponse, and so on), provides a single API to manage the scope of attributes, and so on.
We have previously used the session setattribute () and other methods to set a process can be shared property objects, using the session set properties in the same process can be shared, in addition to the session, there are PageContext, request, Application can also use methods such as setattribute () (see API files for details) to set a Property object that can be shared, except that the properties set by these four objects have a different common scope.
Using the Property object set by PageContext, its common scope is limited to the same JSP page, using the Property object set by request, which can be shared during the same request processing (including forward to other JSP pages). The Property object set by the session object is limited to the same process, and the properties set by the Application object can be shared across the JSP page in the entire Web application.
Take application as an example, you can set some objects as properties to application, and another JSP page can get this Property object at the appropriate time, for example:
<%
String attr = "String Object";
OUT.PRINTLN ("Set attribute to Application:" + attr);
Application.setattribute ("str", attr);
%>
We'll connect to this JSP page to perform the property setting, and then we'll connect to the JSP page:
<%
String attr = (string) application.getattribute ("str");
Out.println ("Get application attribute:" + attr);
%>
Since we have previously set the string object in the application as a property, so we can get the previous set of objects in the above page, the same reason, you can also set properties in the same way to PageContext, request, session and other objects, The Set Property object can be obtained as long as it is within the allowable scope.
You can use the PageContext object to set properties and specify the scope of the property, instead of using individual PageContext, request, session, application to set, which is what you mentioned earlier, With PageContext providing a single API to manage the scope of the attribute, you can use the following methods to set it up:
GetAttribute (String name, int scope)
SetAttribute (String name, Object value, int scope)
RemoveAttribute (String name, int scope)
The SCOPE can be specified using the following constants: Pagecontext.page_scope, Pagecontext.request_scope, Pagecontext.session_scope, Pagecontext.application_scope, the name of the constant has directly indicated the attribute range, we can change the above two JSP page to the following form:
<%
String attr = "String Object";
OUT.PRINTLN ("Set attribute to Application:" + attr);
Pagecontext.setattribute ("str", attr, Pagecontext.application_scope);
%>
<%
String attr = (string) pagecontext.getattribute ("str", pagecontext.application_scope);
Out.println ("Get application attribute:" + attr);
%>
JSP built-in objects and El built-in objects