JSP Tutorial (3) - Use of "Predefined Variables" in JSP

zhaozj2021-02-16  54

In order to simplify the code in the JSP expression and the scriptlets, 8 automatic defined variables are provided, sometimes referred to as Implicit Objects. They are: Request, Response, Out, Session, Application, Config, PageContext, and Page. Let's take a detailed understanding of them. Request is associated with Request's HTTPSERVLETREQUEST class so that you can get Request's parameters (via getParameter method), Request's type (GET, Post, Head, etc.), and introduced HTTP heads (cookies, refrer, etc.) . Strictly speaking, Request is a subclass of class servletRequest rather than HTTPSERVLETREQUEST classes, in fact, if the Request's protocol is not HTTP, then it hardly works. Response is connected to the client's Response with HttpservletResponse. Note that because the output stream is placed in buffer, the HTTP status code and the response head can be set, although it is not allowed to send it to the client in the standard servlets. OUT This uses the PrintWriter class to send output to the client. However, in order to enable the Response object, you can use the use of a PRINTWRITE class using buffer version JSpWriter. Using the properties of the session page Directive, you can define the size of the buffer, or even shut down the buffer after using the buffer property. Please also note that OUT is only used in ScriptleTs because the JSP expression is automatically placed in output stream, so you need a little declaration of OUT. The Session application is associated with the Request. Because Session is automatically created, this variable can still be bound even if there is no introduced session. There is an exception that if you use the Page Directive to close the session, you will cause an error when you try to use the Session (when the JSP page is converted to servlet). Application uses the ServeTContext class to get by using getServletConfig (). GetContext (). Config is an object of a ServletConfig class. PageContext This is a new class PageContext in JSP, uses when practicing the characteristics of a particular server, such as increasing the efficiency of JSPWriters. If you access this class instead of direct, your code will still run the JSP / Servlet engine in the Rule. Page is not very useful in Java, it is just the time used to save the language in the script is not Java.

转载请注明原文地址:https://www.9cbs.com/read-20427.html

New Post(0)