JSP Tutorial (iii) using _JSP programming for "predefined variables" in--jsp

Source: Internet
Author: User
To simplify the code in JSP expressions and scriptlets, there are 8 types of automatically defined variables, sometimes called implicit objects (intrinsic objects). They are: request,response,out,session,application,config,pagecontext, and page. Let's take a look at them in detail below.

Request

Associated with request is the HttpServletRequest class, which allows you to get the parameters of the request (through the GetParameter method), the type of request (Get,post,head, and so on), And the introduction of HTTP headers (cookies,referer, etc.). In strict terms, the request is a subclass of class ServletRequest rather than a httpservletrequest class, in fact, if the request protocol is not HTTP, it will hardly work.

Response

The response of the client is connected to the HttpServletResponse. Note that because the output stream is buffered, you can set the HTTP status code and the response header, although it is not allowed to be sent to the client in standard Servlets.

Out

This uses the PrintWriter class to send output to the client. However, in order for the response object to work, you can use a buffered version of the Printwrite class JspWriter. Using the Properties page directive of the session, you can define the size of the buffer yourself, or even turn off buffering after you use the Buffer property. Also note that out is only used in scriptlets, because the JSP expression is automatically placed in the output stream, so there is very little need for explicit declaration out.

Session

Apply the HttpSession class that is associated with the request. Because the session is created automatically, this variable can still be bound even if there is no one introduced. One exception is that if you close the session with Page directive and then try to use session, it will cause an error (when the JSP page is converted to the servlet).

Application

Use the Serveletcontext class and get it by using Getservletconfig (). GetContext ().

Config

is an object of a ServletConfig class.

PageContext

This is a new class PageContext in the JSP that is used to refine the characteristics of a particular server, such as improving the efficiency of jspwriters execution. If you access this class instead of directly, your code will still run on the "rules" of the Jsp/servlet engine.

Page

is not very useful in Java, it is only used to save time when the script's language is not 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.