Eight implicit objects in jsp

Source: Internet
Author: User

1. page Object
The page object represents jsp (the preferred choice for SUN Enterprise applications), and more accurately, it represents the Servlet after jsp (the preferred choice for SUN Enterprise Applications) is translated, it can call the methods defined by the Servlet class.

Ii. config object
The config object stores some initial Servlet data structures.
The config object is implemented on the javax. servlet. ServletConfig interface. It has the following four methods:
Public String getInitParameter (name)
Public java. util. Enumeration getInitParameterNames ()
Public ServletContext getServletContext ()
Public Sring getServletName ()

Iii. request object
The request object contains information about all requests, such as the request source, header, cookies, and request-related parameter values.
The request object implements the javax. servlet. http. HttpServletRequest interface. The methods provided can be divided into four categories:
1. Storage and acquisition of attributes;
Void setAttribute (String name, Object value): set the value of the name attribute to value.
Enumeration getAttributeNamesInScope (int scope) gets attributes of all scope ranges
Object getAttribute (String name) obtains the value of the name attribute.
Void removeAttribute (String name) removes the value of the name attribute.
2. Methods for obtaining Request Parameters
String getParameter (String name) gets the name parameter value
Enumeration getParameterNames () Get all parameter names
String [] getParameterValues (String name) Get the parameter values of all names
Map getParameterMap () gets a Map that requires Parameters
3. Methods for obtaining the HTTP header of a request
String getHeader (String name) gets the name header
Enumeration getHeaderNames () get all header names
Enumeration getHeaders (String name) gets the headers of all names
Int getIntHeader (String name) gets the header of the integer name
Long getDateHeader (String name) gets the date type name header
Cookie [] getCookies () get cookies related to requests
4. Other Methods
String getContextPath () Get the Context path (that is, the platform name)
String getMethod () get http method (GET, POST)
String getProtocol () gets the used protocol (HTTP/1.1, HTTP/1.0)
String getQueryString () gets the request parameter String. However, the HTTP method must be GET
String getRequestedSessionId () obtains the Session ID of the user end.
String getRequestURI () gets the request URL, but does not include the request parameter String
String getRemoteAddr () Get the user's IP address
String getRemoteHost () obtains the host name of the user.
Int getRemotePort () gets the user's host port
String getRemoteUser () Get the user name
Void etCharacterEncoding (String encoding) sets the encoding format to solve the problem of passing Chinese characters in the form.

4. response object
The response object mainly transmits the result of processing data from jsp (preferred for SUN Enterprise Applications) back to the client.
The response object implements the javax. servlet. http. HttpServletResponse interface. The method provided by the response object.
1. How to set the table Header
Void addCookie (Cookie cookie) adds a cookie
Void addDateHeader (String name, long date) adds the value of the long type to the name header.
Void addHeader (String name, String value) adds a String type value to the name header.
Void addIntHeader (String name, int value) adds the int type value to the name header.
Void setDateHeader (String name, long date) specifies the value of the long type to the name header.
Void setHeader (String name, String value) specifies the String type value to the name header
Void setIntHeader (String name, int value) specifies the int type value to the name header
2. How to set the response status code
Void sendError (int SC) status code)
Void sendError (int SC, String msg) Transfer status code and error message
Void setStatus (int SC) Status Code
3. Method Used for URL rewriting (rewriting)
String encodeRedirectURL (String url) encode the URL using the sendRedirect () method

V. out object
The out object can output the result to the webpage.
Out is mainly used to control the buffer and output stream used to manage the output ).
Void clear () clears the content of the output buffer
Void clearBuffer () clears the content of the output buffer
Void close () close the output stream and clear all content
Int getBufferSize () gets the current buffer size (KB)
Int getRemaining () obtains the remaining buffer size (KB) after use)
Boolean isAutoFlush () returns true, indicating that the buffer is cleared automatically when the buffer is full; false indicates that the buffer is not cleared automatically and Exception Processing is triggered.

Vi. session Object
The session Object indicates the session status of an individual user.
Implement the javax. servlet. http. HttpSession interface and the methods provided by the HttpSession interface.
Long getCreationTime () indicates the time the session is generated, in milliseconds.
String getId () gets the session ID
Long getLastaccess (the favorite of small websites) edTime () gets the time when the user finally sends a request through this session
Long getMaxInactiveInterval () gets the maximum time when the session is not active. If this time is exceeded, the session will become invalid.
Void invalidate () cancels the session object and completely discards the content stored in the object
Boolean isNew () determines whether the session is "new"
Void setMaxInactiveInterval (int interval) sets the maximum time when the session is not active. If this time is exceeded, the session will become invalid.

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.