Nine implicit JSP objects, and nine hidden jsp objects

Source: Internet
Author: User

Nine implicit JSP objects, and nine hidden jsp objects

1. Nine implicit objects in jsp

Request HttpServletRequest

Response HttpServletResponse

Session HttpSession

Application ServletcContext

Config ServletConfig

Exception (used in special cases)

Page this (this JSP page)

Out JspWriter (PrintWriter with buffer)

PageContext (allows common Java classes to access WEB resources, and custom labels are commonly used)

2. session
(1) when accessing the jsp page, the default web server creates a session
(2) when accessing the servlet, you must use request. getSession () to create a session.
(3). In the case of forwarding and redirection, the session domain will not be destroyed

3. application = ServletContext object

4. config
Obtain jsp ing information in the web. xml file

5. page: indicates the current jsp page. Only the error in the jsp tag indicates the current domain object. In the code, it indicates that the current domain object can only be PageContext

6. out implicit object

(1) The. out implicit object is used to send text data to the client.
(2) The. out object is returned by calling the getOut method of the pageContext object. Its function and usage are very similar to the PrintWriter object returned by the ServletResponse. getWriter method.
(3 ). the out implicit object type on the JSP page is JspWriter. JspWriter is equivalent to a PrintWriter with the cache function. You can adjust the cache size by setting the buffer attribute of the page instruction on the JSP page, even disable its cache.
(4 ). the out object calls ServletResponse only when the content written to the out object meets any of the following conditions. the getWriter method returns the PrintWriter object to write the content in the buffer zone of the out object to the buffer zone provided by the Servlet engine:
(5). Set the buffer attribute of the page command to disable the cache function of the out object.
The buffer of the out object is full. The JSP page ends.

Working principle of out:


7. exception: This object can be created only when <% @ isErroPage = "true" %>. Otherwise, the container will not be created.

8. pageContext

(1). the PageContext domain object is limited to the current jsp page. When the jsp page is displayed, the original PageContext domain object is destroyed. If no value is obtained, null is returned.
(2) The PageContext domain object can save the corresponding values in one of the four specified domain objects.
PageContext. setAttribute ("name", "Silk", PageContext. REQUEST_SCOPE );
(3) The PageContext domain object can retrieve the corresponding values from one of the four specified domain objects.
<% = PageContext. getAttribute ("name", PageContext. APPLICATION_SCOPE) %>
(4). PageContext. findAttribute ("name ")
It uses the name as the key and searches for the corresponding values in the four domain objects in sequence. If the values cannot be found, null is returned.

9. Four domain objects

Lifecycle diagrams of four domain objects:



Map of four domain objects:


(1) Create pageContext when executing pageContext jsp and destroy pageContext when jsp page ends
(2). The request is created when the customer requests the server, and the request ends and the request is destroyed.
(3) When the session client requests the server for the first getSession, the server creates a session, and the session has not been used for xx (or the session. invalidate method is called), and the server destroys the session.
(4). the application (servletContext) is created when the web application is started, and the web application is destroyed when it is stopped.


10. Under what circumstances does the domain use?
(1). Under what circumstances do I use the request domain? If the data is useless after reading the data during development, the data should be stored in the request domain. For example, when you read news, the news is useless data when you read it. When the servlet obtains news data, it should be displayed in the request to jsp.

(2). Under what circumstances will the session domain be used? If the user still needs to use the data after reading the data during program development, the data should be stored in the session domain. for example, the purchased item is user data. After the data is generated, the user needs to wait for a while for checkout. Then, the program should store the data in the user's session.

(3). Under what circumstances will the application domain be used? If the data is generated during the development of the program, the data will not only be used for a while, but also for others, it should exist in the application domain, such as web chat rooms and user chat data, this data is not only visible to users for a while, but also to others.


What are the nine implicit objects in jsp?

JSP's nine implicit objects:
Request response out session application pageContext page config exception the implicit object does not need our new object. We can directly use the object on the page,

What are the nine implicit objects in Java and their functions?

JSP has the following nine basic built-in components:
Request client request, which contains parameters from the GET/POST request
Response returned from the response webpage to the client
The pageContext page is managed here.
Session-related session Period
Content being executed by application servlet
Out is used to send response output.
Configuration servlet framework
Page JSP page itself
Exception for the error webpage, exceptions not captured

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.