Detailed explanation of the nine built-in JSP objects

Source: Internet
Author: User

Built-in object features:

1. It is provided by JSP specifications and does not need to be instantiated by writers.

2. Web Container Implementation and Management

3. All JSP pages can be used

4. It can only be used in the expression or code segment of the script element (<% = use built-in object %> or <% use built-in object %>)

Common built-in objects:

1. Output input object: request object, response object, and out object

2. communication control objects: pageContext objects, session objects, and application objects

3. Servlet object: page Object and config object

4. Error Handling object: exception object

 


Common Object methods:

1. out object (data stream javax. servlet. jsp. jspWriter)

Method Name
Description
 
Print or println
Output Data
 
NewLine
Output line feed characters
 
Flush
Output buffer data
 
Close
Close output stream
 
Clear
Clears the data in the buffer but does not output it to the client.
 
ClearBuffer
Clear the data in the buffer and output it to the client.
 
GetBufferSize
Obtain the buffer size
 
GetRemaining
Obtain the unoccupied space in the buffer.
 
IsAutoFlush
Automatic output or not
 

2. request object (request Information javax. servlet. http. HttpServletrequest)

Method Name
Description
 
IsUserInRole
Determine whether the authenticated user belongs to a member group
 
GetAttribute
Obtains the value of a specified property. If the property does not exist, Null is returned.
 
GetAttributeNames
Obtains a set of all attribute names.
 
GetCookies
Get all Cookie objects
 
GetCharacterEncoding
Get the character encoding method of the request
 
GetContentLength
Returns the length of the Request body. If you are not sure, return-1.
 
GetHeader
Obtains the header value of a specified name.
 
GetHeaders
Obtains all values of the specified name header, an enumeration.
 
GetHeaderNames
Obtains the names of all headers, one enumeration.
 
GetInputStream
Returns the request input stream to obtain the data in the request.
 
GetMethod
How to obtain data transmitted from a client to a server
 
GetParameter
Obtains the specified name parameter value.
 
GetParameterNames
Obtains the names of all parameters, one enumeration.
 
GetParameterValues
Obtains all values of a specified name parameter.
 
GetProtocol
Obtain the protocol name that the client sends data to the server.
 
GetQueryString
Obtain the query string sent to the server using the get method.
 
GetRequestURI
Obtain the client address of the request string
 
GetRemoteAddr
Obtain the Client IP Address
 
GetRemoteHost
Obtain the client name
 
GetSession
Obtain request-related sessions
 
GetServerName
Get server name
 
GetServerPath
Obtain the path of the client request file
 
GetServerPort
Get the server port number
 
RemoveAttribute
Delete an attribute in the request
 
SetAttribute
Set the specified name parameter value
 

 


3. response object (responding to javax. servlet. http. HttpServletResponse)

Method Name
Description
 
AddCookie
Add a Cookie object
 
AddHeader
Add the specified name header of an Http File
 
ContainsHeader
Determine whether the specified Name Http File Header exists
 
EncodeURL
Use sessionid to encapsulate a URL
 
FlushBuffer
Forcibly send the content of the current buffer to the client
 
GetBufferSize
Returned buffer size
 
GetOutputStream
The output stream object returned to the client.
 
SendError
Send error message to client
 
SendRedirect
Send the response to another location for processing
 
SetContentType
Set the response MIME type
 
SetHeader
Sets the Http file header with the specified name.
 

4. session Object (session javax. servlet. http. HttpSession)

Method Name
Description
 
GetAttribute
Obtains the attributes of a specified name.
 
GetAttributeNames
Obtains all attribute names in a session, one enumeration.
 
GetCreationTime
Returns the session creation time.
 
GetId
Get session identifier
 
GetLastAccessedTime
Returns the time when the last request was sent.
 
GetMaxInactiveInterval
Returns the unit of survival time of the session object in 1‰ seconds.
 
Invalidate
Destroy session Object
 
IsNew
Will each request generate a new session object?
 
RemoveAttribute
Deletes an attribute of a specified name.
 
SetAttribute
Set the attribute value of a specified name
 

5. pageContext object (page context javax. servlet. jsp. PageContext)

Method Name
Description
 
Forward
Redirect to another page or Servlet component
 
GetAttribute
Obtains the attribute value of a specified name in a range.
 
FindAttribute
Search for attributes of a specified name by range
 
RemoveAttribute
Deletes the attribute of a specified name in a range.
 
SetAttribute
Set the attribute value of a specified name in a range
 
GetException
Returns the current exception object.
 
GetRequest
Returns the current request object.
 
GetResponse
Returns the current response object.
 
GetServletConfig
Returns the ServletConfig object of the current page.
 
GetServletContext
Returns the ServletContext object shared by all pages.
 
GetSession
Returns the session object of the current page.
 

 

6. application Object (application javax. servlet. ServletContext)

Method Name
Description
 
GetAttribute
Obtains the attribute value of a specified name in an application object.
 
GetAttributeNames
Obtains the names of all attributes in an application object, an enumeration.
 
GetInitParameter
Returns the initial parameter value of the specified name in the Application object.
 
GetServletInfo
Returns the current version of the Servlet compiler.
 
SetAttribute
Set the attribute value of the specified name in the Application Object
 

7. config object (Servlet configuration information javax. servlet. ServletConfig)

Method Name
Description
 
GetServletContext
Returns the environment object of the executed Servlet.
 
GetServletName
Returns the name of the Servlet to be executed.
 
GetInitParameter
Returns the initial parameter value of the specified name.
 
GetInitParameterNames
Returns all the initial parameter names in the JSP, an enumeration.
 

8. page object (the current JSP instance, java. lang. object)

It indicates that JSP is compiled into Servlet and can be used to call the methods defined in the Servlet class.

9. exception object (runtime exception, java. lang. Throwable)

The result of the called error page can only be used on the error page,

In the page command, set: <% @ page isErrorPage = "true" %>

 

Request (Javax. servlet. ServletRequest) contains information about browser requests. This object can be used to obtain header information, cookies, and Request parameters in the Request.

Response (Javax. servlet. ServletResponse) is stored as the Response returned to the user as the JSP page processing result. It also provides methods for setting response content, response headers, and redirection (such as cookies and header information)

Out (Javax. servlet. jsp. JspWriter) is used to write content to the output stream of the JSP page instance. It provides several methods for you to send output results back to the browser.

PageContext (Javax. servlet. jsp. PageContext) describes the running environment of the current JSP page. You can return access to other implicit objects and their attributes on the JSP page. In addition, it also implements the transfer of control from the current page to other pages.

Session (javax. servlet. http. HttpSession) Session object stores information about this Session. You can also assign attributes to a Session. Each attribute has a name and a value. Session objects are mainly used to store and retrieve attribute values.

Application (javax. servle. ServletContext) stores the servlet running JSP pages and context information of any Web Components in the same Application.

Page (Java. lang. Object) indicates the servlet instance of the current JSP Page

Config (javax. servlet. ServletConfig) is used to access the initialization parameters of the servlet instance.

Exception (Javax. lang. Throwable) is forwarded to the JSP error page when an Exception is thrown on a page. This object is provided to handle errors in JSP. <% @ Page isErrorPage = "true" %>

 

 

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.