A total of nine large built-in objects:
Request, response, out, session, application, PageContext, page, config, exception
Built-in objects (also known as hidden objects) are objects that can be used directly in the JSP without creating (created by Server < container >).
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
Page currently has the shortest effective time (page execution period)
Request HTTP requests start at the end of the period
Session HTTP sessions start at the end of the period
Application server starts to stop this time
Out: Belongs to class JspWriter
Request: Implements the HttpServletRequest interface (this interface inherits from the ServletRequest interface)
Response: Implements the HttpServletResponse interface (this interface inherits from the Servletresponse interface)
Session: Implements the HttpSession interface
Application Object Implementation Interface ServletContext
1.out objects: outputting information to clients
There are two main methods, print and println, which do not implement line breaks
Example: output a paragraph of bold text
Out.print ("<b> This is a bold text </b>");
We can use Out.print to output any information to the client, such as outputting a table, and so on.
Use System.out.println () on the Web page to output information to the console.
2.request object: Gets the information that the client passes to the server.
Examples of common methods of request
(1) getparameter
Gets the value of a parameter that the client passes to the server
(2) getparameternames
Span style= "font-size:18pt" > Gets the name of all parameters passed to the server by the client
(3) getparametervalues
get all values of one parameter (for example, checkbox)
&NBSP;
(4) SetAttribute
(5) getattribute attribute= Properties
(6) removeattribute
Used primarily in the Struts framework
properties that must be set in the same request to get to
(7) getattributenames
(8) GetCookies, when speaking cookies, speak alone.
Cookie cookies, a technology that stores personal information on the client
(9) getcharacterencoding
(Ten) Getcontentlength
(one) GetMethod
(Getrequesturl)
(GETREMOTEADDR)
(getServerName)
(Getserverport)
(Getservletpath)
(Getcontextpath)
(getheader,getheaders,getheadernames)
Header : Web header, Web control information
Request.getheader ("Referer") from the Web page
3.response object: Output information to client browser, respond to customer's request
4.session: Session Expiration time, tomcat default is 30 minutes, can be set. The session space for each user is isolated.
5.application Application Objects
application,session,request: You can set properties by setattribute, use GetAttribute to get properties, but the visible range is different.
The properties that are set by the Application object, all sessions are visible, and the properties set by the session object are visible only in the same session.
Similarly, the request that was previously mentioned, the property that it sets, is visible only between the same request.
The application does not expire, is valid during the entire server run, and is lost after the server restarts.
some other methods of application:
Application.getrealpath ()
6.page Objects
The JSP Web page itself, the Page object, is an instance of the current page-converted Servlet class. From the code of the converted Servlet class, you can see this relationship: Object page = this; in JSP pages, page objects are seldom used.
7.config object: The main function is to obtain the server configuration information.
common methods are getinitparameter and getinitparameternames to obtain parameters for servlet initialization.
A config object can be obtained by using the Getservletconfig () method of the Pageconext object. When a servlet initializes, the container passes some information through the Config object to the servlet. Developers can provide initialization parameters for servlet programs and JSP pages in the application environment in the Web. xml file.
8.exception Objects
specify ErrorPage with page directives in files that may produce errors
in the specified errorpage, set the iserrorpage= "true" page directive, and then use the exception object to get the error message.
<% @page errorpage= "error.jsp"%>
The session is also required to set page directives on the pages.
9.pageContext Objects
function: A. You can use it to get a handle to the other eight built-in objects (the handle of itself is not acquired)
out Pagecontext.getout ()
request Pagecontext.getrequest ();
response Pagecontext.getresponse ();
session pagecontext.getsession ();
application Pagecontext.getservletcontext ();
config pagecontext.getservletconfig ();
exception Pagecontext.getexception ();
page Pagecontext.getpage ();
B. You can use it to set or get the value of a variable within 4 different ranges (page,request,session,application)
The value set is valid only on this page
Pagecontext.setattribute ("name", "John");
The value set is valid for the same request.
Pagecontext.setattribute ("name", "John", Pagecontext.request_scope))
equivalent to Request.setattribute ("name", "John");
The value set is valid in the same session request.
Pagecontext.setattribute ("name", "John", Pagecontext.session_scope))
equivalent to Session.setattribute ("name", "John");
The value set is valid throughout the application.
Pagecontext.setattribute ("name", "John", Pagecontext.application_scope))
equivalent to Application.setattribute ("name", "John");
JSP nine large built-in objects and four scope of the detailed