JSP implicit object (1), jsp implicit object

Source: Internet
Author: User

JSP implicit object (1), jsp implicit object
1. Initial appearance of JSP implicit objects;

(1) There will always be nine hidden objects during the interview, which will be described in detail below;

(2) In JSP pages, information such as request requests and response responses are often processed. to simplify the program design, JSP defines nine commonly used implicit objects (implicit objects ),

These hidden objects do not need to be created with the new keyword on the JSP page, but are created and managed by the Servlet container and passed to the Servlet implementation class on the JSP page for use. (For example)


(3) In the _ jspService () method of the Servlet implementation class on the JSP page, the code segment for automatically initializing the JSP implicit object is as follows:



Therefore, JSP implicit objects are internally defined in the _ jspService () method of servlet implementation class on the JSP page. Therefore, jsp pages can be directly used in <%> or <% = %>!

II. out implicit object; (1) out object output information mainly includes print (), println () and newline (). (2) buffer-related methods: there are several methods related to the output buffer in the out object:

1. flush () method

Flush () is used to refresh the stream. In Java, I/O operations are converted into stream operations. Out. the write () output information is temporarily stored in the stream object buffer. The refresh operation transmits the information in the buffer to the target object for processing. If the target object is a second or byte stream, refresh it, So calling the flush () method will refresh the buffer in all output stream object chains. If the buffer zone is full, this method is automatically called to output information in the buffer zone.

If the stream has been closed, calling print () or flush () will cause an IOException;

2. clear () method
Clear () indicates clearing information in the buffer. If the buffer is empty, executing this method will cause an IOException.
3. clearBuffer ()
ClearBuffer () is similar to clear (). It clears the output buffer and returns the result. Unlike clear (), clearBuffer does not throw an exception.

4. getBufferSize ()
GetBufferSize () returns the size of the output buffer, in bytes. If there is no buffer, 0 is returned.
5. getRemaining ()
GetRemaining () returns the remaining idle space in the buffer, in bytes.

6. isAutoFlush ()
IsAutoFlush () returns a real value to indicate whether the buffer is automatically refreshed.


3. request implicit object; see article: http://blog.csdn.net/xlgen157387/article/details/39136725


What is the implicit object of jsp?

1. The out comes from the java. io. Writer class, which is used to send the output to the client.
2. The request comes from the javax. servlet. http. HttpServletRequest interface. It is associated with every HTTP request.
3. response comes from javax. servlet. http. HttpServletResponse. The response object is used to return the obtained data to the client.
4. pageContext provides a namespace for accessing JSP pages. It also provides access to other JSP implicit objects.
5. The session is from javax. servlet. http. HttpSession. It is used to store client request information, so it is stateful interactive.
6. The application comes from javax. servlet. ServletContext.
7. config comes from ServletConfig, which contains the configuration information of the WEB application where the current JSP/Servlet is located.
8. page comes from the instantiation of the currently accessed JSP page. It actually uses the Servlet converted from JSP.
9. exception is used to capture exceptions thrown by JSP. It is available only when the JSP page attribute isErrorPage = true.

What is out in JSP? It is an implicit object. I know it.

Out is a built-in object in jsp, called an output stream object. It is not a method, so it cannot be output. This object can be output by calling the print () method, and other methods such as newLine (), flush (), close ()
Out. print () is the output, out. newLine () is the line feed, out. flush () is the output buffer,
The last one is to close the output stream. Study other built-in objects

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.