Java Basics---JSP built-in object

Source: Internet
Author: User

In order to simplify the development of the user, the JSP provides nine built-in objects that will be instantiated by the container for the user, and the user can use it directly, rather than having to instantiate the object through the keyword new as in Java.

No.

Built-in objects

Type

Describe

1

PageContext

Javax.servlet.jsp.PageContext

JSP's page container

2

Request

Javax.servlet.http.HttpServletRequest

Get the user's 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 each user's information

5

Application

Javax.servlet.ServletContext

Represents shared information for all users

6

Config

Javax.servlet.ServletConfig

Server configuration, can get initialization parameters

7

Out

Javax.servlet.jsp.JspWriter

Page output

8

Page

Java.lang.Object

Represents a servlet instance that is represented from this page

9

exception

Java.lang.Throwable

Represents an exception that occurs on a JSP page and does not work in the error page

In the JSP provides four kinds of attributes to save the scope, so-called attribute preservation scope, refers to a set of objects, can be saved in the number of pages and can continue to use

Four attribute ranges:
    1. PageContext: The property is saved in only one page and is not valid after jumping.
    2. Request: Saved only in one request, the server is still valid after a jump.
    3. Session: In a conversation scope, any jump can be used, but the new browser is not available.
    4. Application: Save on entire server, all users can use

Public Object GetAttribute (String name)

class= oa1 "width=" 426 "" >
No.

method

type

Description

public void SetAttribute (String name,object o)

normal

Set the name and contents of the property

2

normal

Get property based on property name

3

public void RemoveAttribute (String name)

normal

Delete specified properties

The page property range (denoted by PageContext, but is generally used to refer to this range as the page range) indicates that a property is set on this page and cannot be obtained after a jump.

Request Property Scope ( if the property can continue to be saved after a server jump, you can use the Request property scope operation, which indicates that all settings will remain intact after the server jumps )

Understanding of the scope of the request attribute: request represents the client's requests, normally, a single request server will only give one response, then this time if the server-side jump, the requested address bar has not changed, so it is equivalent to a response, and if the address bar changed, is equivalent to making a second request, the content of the first request must have disappeared, so it cannot be obtained.

Session Property Scope (if you now want a property set, can be in any page related to the Settings page, you can use the Session property scope, after using the session to set the properties, whether the client jump or server-side jump, Can be obtained as long as the property is set)

Application Property Scope (if you want to set a property now so that all users (each session) can see it, you can set the property scope to application so that the property is stored on the server. )

Other objects:

The primary purpose of the response object is to respond to the client's request and send the results back to the client after the Web server has processed it. The response object belongs to an instance of the Javax.servlet.http.HttpServletResponse interface, and the HttpServletResponse interface is defined as follows: public interface HttpServletResponse extends servletresponse   The Config object is an instantiated object of the Javax.servlet.ServletConfig interface, and the main function is to obtain some initialization configuration information. Common methods: public string Getinitparameter (string name) public enumeration Getinitparameternames ()    The Out object is an instantiated object of the Javax.servlet.jsp.JspWriter class, the main function is to complete the output of the page, using the println () or the print () method output, but from the actual development, direct use of the out object is less likely, will use an expression to complete the output operation. The Out object defines several actions: public int getbuffersize () public int getremaining ()    The PageContext object is an instance of the Javax.servlet.jsp.PageContext class, mainly representing the context of a JSP page, in which, in addition to the property operations previously explained, some of the following methods are defined: public abstract void Forward (string relativeurlpath) throws Servletexception,ioexceptionpublic void include (string Relativeurlpath) throws Servletexception,ioexceptionpublic ServletConfig Getservletconfig () public ServletContext Getservletcontext () public servletrequest getrequest () public servletresponse getResponse () public httpseSsion getsession ()

Java Basics---JSP built-in objects in a detailed article

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.