Use of common predefined variables in JSP development

Source: Internet
Author: User

JSP expressions and code in scriptlets provide 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.

◆ JSP pre-defined variable request

The HttpServletRequest class is associated with the request, so that you can obtain the request parameters through the getParameter method), the request type GET, POST, HEAD, and so on), and The introduced HTTP header cookies, referer, etc ). 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 of JSP pre-defined Variables

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 of JSP pre-defined Variables

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.

◆ JSP predefined variable 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 of JSP predefined Variables

Use the ServeletContext class and get it by using getServletConfig (). getContext.

◆ JSP predefined variable config

Is an object of the ServletConfig class.

◆ PageContext of JSP predefined Variables

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 br>

◆ Page of JSP predefined Variables

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

These are some common usage overview of JSP pre-defined variables. Do you have a certain understanding of them?

  1. How Tomcat improves performance on JSP pages
  2. Use of scripts Based on JSP tutorials
  3. JSP tutorial basics-HTML form demonstration
  4. Five Aspects to get started with JSP
  5. JSP entry-level website environment setup steps

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.