1. jsp implicit object
1. jsp implicit objects are instances of a group of classes managed by JSP Container loading.
* JSP implicit objects are defined in the _ jspservice method. Therefore, they can only be used in expressions and scriptlet.
2. jsp implicit objects are classified into four categories:
* Input and Output objects: httpservletrequest's request, httpservletresponse's response, and jspwriter's out;
* Scope communication objects: httpsession session, application of servletcontext, and pagecontext of pagecontext;
* Servlet object: page of the object, config of servletconfig;
* Error object: throwable exception;
3. servlet code snippet:
......
Public void _ jspservice (httpservletrequest request, httpservletresponse response)
Throws java. Io. ioexception, servletexception {
Pagecontext = NULL;
Httpsession session = NULL;
Servletcontext application = NULL;
Servletconfig Config = NULL;
Jspwriter out = NULL;
Object page = this;
Jspwriter _ jspx_out = NULL;
Pagecontext _ jspx_page_context = NULL;
......
}
2. Input and Output objects: control the input and output of the page;
1. httpservletrequest request: encapsulation of client request information.
* Scope:
One request to the response stage. In this phase, objects in the forwarding and page are shared.
The request object is re-created for each request.
2. httpservletresponse response: encapsulation of server response information.
* It is used to set response headers, cooike, and other response information.
3. jspwriter: outputs data in the form of a forward stream. It is the Cache version of printwriter and uses the buffer attribute of the page command to set the buffer size.
* Several methods related to cache operations:
Flush: refresh the buffer;
Isautoflush: determines whether the out object is automatically refreshed. Set automatic refresh in the buffer attribute of the page command.
Clear and clearbuffer: Clear the content in the buffer. If the buffer is "refreshed", the former throws an IO exception, and the latter does not.
* Servlet code snippet:
Out = pagecontext. getout ();
_ Jspx_out = out;
3. Scope communication objects: communication information between JSP pages and Servlet;
1. pagecontext: provides a unified portal to access other hidden objects, their attributes, and their own attributes to maintain data sharing between different components on the same page.
* Javax. servlet. jsp. pagecontext;
* Scope:
Page scope. Each page and request has a different pagecontext object.
When the include command is used to include a page, the contained file shares the pagecontext object. JSP: include action is not allowed.
Put this property in the request.
Servlet and JSP pages do not share pagecontext objects.
* Access, set, and remove attributes of other hidden objects: scope is a pagecontext constant.
Getattribute (string name, int scope );
Setattribute (string name, int scope );
Removeattribute (string name, int scope );
The removeattribute (string name) method removes the specified attributes of all range classes.
* Searches for the specified attributes in all ranges in the order of page, request, session, and application.
Findattribute (string name );
* Servlet code snippet:
......
Private Static final jspfactory _ jspxfactory = jspfactory. getdefafactory Factory ();
......
Public void _ jspservice (httpservletrequest request, httpservletresponse response)
......
Pagecontext = _ jspxfactory. getpagecontext (this, request, response, null, true, 8192, true );
Pagecontext _ jspx_page_context = NULL;
_ Jspx_page_context = pagecontext;
Application = pagecontext. getservletcontext ();
Config = pagecontext. getservletconfig ();
Session = pagecontext. getsession ();
Out = pagecontext. getout ();
......
_ Jspxfactory. releasepagecontext (_ jspx_page_context );
......
}
2. httpsession: encapsulate the session information of the current request for session tracking.
* Servlet code snippet:
Session = pagecontext. getsession ();
2, servletcontext Application
* Scope: When a web application is running, all pages share the object.
* Servlet code snippet:
Application = pagecontext. getservletcontext ();
4. servlet object: Environment Information of JSP pages;
1. Object page: reference of the servlet object during the current request.
* You can use page to access the generated servlet class members and methods. The page command is the application of this object.
* Scope:
Each time a JSP page is requested, it is created and destroyed after request forwarding or response.
Objects in this range can only be accessed on the page where the object is created.
The pagecontext object belongs to the page range.
* Servlet code snippet:
Object page = this;
2. servletconfig config: servlet initialization information.
5. Error object: Process page errors;
* Java. Lang. throwable exception: An exception occurs when the JSP page is running.
** This object can only be used on error pages (pages with iserrorpage = true in the page command.