Use of "predefined variables" in JSP

Source: Internet
Author: User

To simplify JSP expressions and scriptlets code, eight automatically Defined variables are provided, sometimes called implicit objects (inherent objects ). They are: request, response, out, session, application, config, pageContext, and page. Let's take a closer look at them. The request is associated with the HttpServletRequest class, so that you can obtain the request parameters (through the getParameter method), request types (GET, POST, HEAD, and so on ), and the introduced HTTP header (cookies, Referer, and so on ). Strictly speaking, a request is a subclass of the ServletRequest class rather than the HttpServletRequest class. In fact, if the request protocol is not HTTP, it will hardly work. Response connects the client's response to HttpServletResponse. Note that because the output stream is buffered, you can set the HTTP status code and response Header, even though it cannot be sent to the client in standard servlets. Out the PrintWriter class is used to send the output to the client. However, to make the response object valid, you can use a buffer version of The PrintWrite class JspWriter. By using the session property page ctictive, you can define the buffer size by yourself, or even disable the buffer when the buffer attribute is used. Note that out is only used in scriptlets. Because JSP expressions are automatically put into the output stream, it is seldom necessary to explicitly declare out. The HttpSession class associated with the request. Because the session is automatically created, this variable can still be bound even if no introduced session exists. One exception is that, if you use page ctictive to close the session and try to use the session, it will lead to an error (during JSP page conversion to servlet ). The application uses the ServeletContext class, which is obtained by using getServletConfig (). getContext. Config is an object of the ServletConfig class. PageContext, a new PageContext class in JSP, is used to refine the features of a specific server, for example, improving the execution efficiency of JspWriters. If you access through this class rather than directly, your code will still run in the "rule" JSP/servlet engine. Page is not very useful in JAVA. It is only used to save the time when the script language is not JAVA.

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.