JSP four domain objects with nine built-in objects

What is the built-in objects?

Jsp development in some frequently used objects, such as ServletContext, HttpSession, PageContext  the like;

If every time we need to use these objects in jsp page should create their own hands would be particularly cumbersome.

SUN company when designing jsp, jsp after page load will be created these objects, you only need to use the corresponding object can call the appropriate methods .

The system creates an object called a good built-in objects .

In the servlet program, if the developer wishes to use the session object, the object must be obtained by Request.getSession session ();

In jsp program, developers can directly use the session (system to help us create good session object name is called session) can call the appropriate method.

Nine built-in objects :

Built-in objects Category :

● input and output objects: out objects, response  objects, request  the object

● communication control objects: pageContext objects, session  objects, application  objects

● Servlet objects: page  objects, config  objects

● Error Handling objects: exception  Object

The role of built-in objects:

Objects effect
request It encapsulates a variety of information from the client, the browser
response It encapsulates the corresponding information server
out For the client, the browser output data
session Used to store session information. I.e., data can be shared between different requests from the same user
application It represents the context of the current application. Information can be shared between different users
config Configuration information of the application wrapper class
pageContext JSP page provides access to all the objects and namespaces
page Pointing to the current JSP program itself
exception Encapsulates the information and exception error occurred during execution of the program JSP

Built-in objects parse : ← Click

Four domain object

Domain Category :

● ServletContext 域

● HttpServletRequest 

● HttpSession domain - the first three in the study will be able to come into contact with Servlet 

● PageContext domain - JSP Learning 

The role of domain objects : save data, access to data, data sharing

Save data :

. pageContext setAttribute ( "Content"); // default saved to the page domain 
pageContext. setAttribute ( "Content", domain-wide constant); // save to the specified domain

Four constant domains :

  • PageContext.PAGE_SCOPE
  • PageContext.REQUEST_SCOPE
  • PageContext.SESSION_SCOPE
  • PageContext.APPLICATION_SCOPE

Get Data :

. the pageContext the getAttribute ( "content"); 
. the pageContext the getAttribute ( "name", the range of the constant domain);

Automatic four in the search field data pageContext findAttribute ( "Content");

Four automatic search data field, the order of : Page Domain -> request Domain -> session Domain -> application domain (context domain)

Domain scope

● page domain; only in the current jsp page use (current page)

● request field; the same can only be used in a request (forward)

● session domain; can only be used in the same session (session object) in the (private)

● context domain; use only (global) in the same web application

 

Guess you like

Origin www.cnblogs.com/Dm920/p/11688919.html