One, what is a built-in object?
In JSP development will be used frequently to some objects, such as ServletContext HttpSession PageContext and so on. If we need to use these objects in our JSP pages each time we have to create them ourselves, it will be especially tedious. Sun Company therefore when designing JSP , after the JSP page load completes automatically to help the developer to create these objects, the developer only needs to use the corresponding object to invoke the corresponding method. These systems create good objects that are called built-in objects.
In a servlet program, if the developer wishes to use the session object, it must get the session object through Request.getsession (), while in the JSP program, the session can be used directly in the development ( The system helps us create a good session object name is called the session to call the corresponding method, such as: Session.getid (). Two, nine large built-in objects in the end is which nine big ?
Built-in object name type
request httpservletrequest
response httpservletresponse
config ServletConfig
Application servletcontext
session HttpSession
exception Throwable
page Object (this)
out jspwriter
PageContext
three, to parse several built-in objects
1 Out Object object, object type is JspWriter class, equivalent to PrintWriter with cache (without cache)
Printwriter:write ("content") directly to the browser output content
Jspwriter:writer ("content") writes out content to the JSP buffer
JspWriter the contents of the buffer are written when one of the following conditions is true:
A, the buffer is full.
b, refreshing the buffer
c, close the buffer
d,jsp page Execution 2 PageContext object
The object type of the PageContext is the PageContext, called the context object of the JSP.
PageContext function: Can get eight other built-in objects
Example:
pagecontext.getout ();
Pagecontext.getservletconfig ()
Use scenarios: PageContext objects are frequently used when customizing labels, or when defining a method requires multiple objects, passing a PageContext object solves the problem.
Four, four domain objects in JSP
Category:
ServletContext context domain
httpservletrequet request domain
HttpSession session domain -- The first three are able to access the
PageContext page domain --jsp learning when learning a servlet
The role of Domain objects: Save data, get data, and share data.
Save data:
Pagecontext.setattribute ("content");//Default Save to Page field
pagecontext.setattribute ("Content", field-wide constant);//save to specified domain
//four domain constants
Pagecontext.page_scope
Pagecontext.request_scope
PageContext. Session_scope
Pagecontext.application_scope
Get Data:
Pagecontext.getattribute ("content");
Pagecontext.getattribute ("name", domain-wide constant);//automatically search for data pagecontext.findattribute ("content") in four domains, or automatically search for data in four domains, in order: page field- >request domain->session domain->application domain (context domain) domain scope:
page field: only use (current page) in the current JSP page
request field: Can only be used in the same request (forward)
session field: can only be used in the same conversation (the Sessions object) ( Private)
context domain: can only be used in the same Web application (global)
Five, summary
Insist on learning a little new technology every day, adhere to write blog, this is the summary of today's blog! fighting,bighuan!