Use of predefined variables in the introductory JSP tutorial

Source: Internet
Author: User
Tags object config variables client
js| variables | Tutorial JSP expressions and code in Scriptlets provide 8 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.

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. You can define the size of the buffer yourself by using the Properties page directive of the session. You can even turn off buffering after using 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 by using Getservletconfig (). GetContext () obtained.

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 in the "rules" of the Jsp/servlet engine br>

Page

is not very useful in Java, it is only used to save time when the script's language is not java.



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.