JSP tutorial (III)-Use of "predefined variables" in JSP

Source: Internet
Author: User

To simplify JSP expressions and Code Provides eight automatically Defined variables, 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.

Request

The httpservletrequest class is associated with the request, so that you can get the request parameters (through the getparameter method), the request type (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

The response of the client is connected 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 data 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.

Session

The httpsession class associated with the application and 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 ).

Application

Use the serveletcontext class and get it by using getservletconfig (). getcontext.

Config

Is an object of the servletconfig class.

Pagecontext

This is a new pagecontext class in JSP, used to refine the characteristics of a specific server, such as 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

It is not very useful in Java. It is only used to save the time in the script language rather than in Java.

Related Article

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.