Java basics --- explanation of JSP built-in objects, basics --- jsp

Source: Internet
Author: User

Java basics --- explanation of JSP built-in objects, basics --- jsp
In JSP, nine built-in objects are provided to simplify user development. These built-in objects are instantiated by containers for users and can be directly used by users, instead of using the new keyword to instantiate an object in java.

No.

Built-in object

Type

Description

1

PageContext

Javax. servlet. jsp. PageContext

JSP page container

2

Request

Javax. servlet. http. HttpServletRequest

Obtain user request information

3

Response

Javax. servlet. http. HttpServletResponse

Response Information from the server to the client

4

Session

Javax. servlet. http. HttpSession

Used to save information of each user

5

Application

Javax. servlet. ServletContext

Indicates the shared information of all users.

6

Config

Javax. servlet. ServletConfig

Server configuration to obtain initialization parameters

7

Out

Javax. servlet. jsp. JspWriter

Page output

8

Page

Java. lang. Object

Indicates a Servlet instance displayed from this page.

9

Exception

Java. lang. Throwable

Indicates the exception on the JSP page, which takes effect only on the error page.

In JSP, the storage range of four attributes is provided. The so-called property storage range refers to the number of pages on which a set object can be saved and can be used continuously.

Four attribute ranges:

No.

Method

Type

Description

1

Public void setAttribute (String name, Object o)

Normal

Set the attribute name and content

2

Public Object getAttribute (String name)

Normal

Get attributes by attribute name

3

Public void removeAttribute (String name)

Normal

Deletes a specified property.

The page attribute range (expressed by pageContext, but generally referred to as the page range) indicates that an attribute is set on this page and cannot be obtained after the jump.

Request attribute range (if you want to save the attribute after the server jump, you can use the request attribute range operation. The request attribute range indicates that after the server jump, all settings are retained)

Understanding of the request attribute scope: the request indicates a client request. Under normal circumstances, the server only responds once for one request. In this case, if the request is a server jump, the address bar of the request has not changed, so it is equivalent to a response. If the address bar has changed, it is equivalent to sending a second request, and the content of the first request must have disappeared, therefore, it cannot be obtained.

Session attribute range (if you want to set a property, you can obtain it on any page related to the setting page, you can use the session attribute range, whether it is client jump or server jump, as long as the property is set, it can be obtained)

Application attribute range (if you want to set an attribute to make it visible to all users (each session), you can set the attribute range to application, in this way, the attributes are saved on the server .)

Other objects:

The main function of the response object is to respond to client requests and send the results processed by the WEB server back to the client. The response object belongs to javax. servlet. http. for an instance of the HttpServletResponse interface, the HttpServletResponse interface is defined as follows: the public interface HttpServletResponse extends ServletResponse config object is javax. servlet. the instantiation object of the ServletConfig interface. The main function is to obtain initialization configuration information. Common method: public String getInitParameter (String name) public Enumeration getInitParameterNames () out object is javax. servlet. jsp. the main function of the instantiated object of the JspWriter class is to complete page output operations and Output Using the println () or print () methods. However, from the actual development perspective, the probability of directly using the out object is small, and the output operation is completed using the expression. The out object defines the following operations: public int getBufferSize () public int getRemaining () pageContext object is javax. servlet. jsp. an instance of the PageContext class mainly refers to the context of a JSP page. In addition to the attribute operations described previously, this class also defines the following methods: public abstract void forward (String rule) throws ServletException, IOExceptionpublic void include (String rule) throws ServletException, IOExceptionpublic ServletConfig getServletConfig () public ServletContext getServletContext () public ServletRequest getRequest () public ServletResponse getResponse () public HttpSession getSession ()

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.