1. Page object
The page object represents the JSP itself, more precisely it represents the translated Servlet of the JSP, which can call methods defined by the Servlet class.
2. config object
The config object stores some Servlet initial data structures.
The config object is implemented in the javax.servlet.ServletConfig interface, which has the following four methods:
public String getInitParameter(name)
public java.util.Enumeration getInitParameterNames( )
public ServletContext getServletContext( )
public Sring getServletName()
3. request object
The request object contains all requested information, such as the source of the request, headers, cookies, request-related parameter values, etc.
The request object implements the javax.servlet.http.HttpServletRequest interface, and the methods provided can be divided into four categories:
1. Methods to store and obtain attributes;
void setAttribute(String name, Object value) Set the value of the name attribute to value
Enumeration getAttributeNamesInScope(int scope) Gets the attributes of all scopes
Object getAttribute(String name) Gets the value of the name attribute
void removeAttribute(String name) removes the value of the name attribute
2. Method to obtain request parameters
String getParameter(String name) Gets the parameter value of name
Enumeration getParameterNames() Gets all parameter names
String [] getParameterValues(String name) Gets the parameter values of all names
Map getParameterMap() Gets a Map that requires parameters
3. Methods to obtain request HTTP headers
String getHeader(String name) Get the header of name
Enumeration getHeaderNames() gets all header names
Enumeration getHeaders(String name) Gets the headers of all names
int getIntHeader(String name) Gets the header of integer type name
long getDateHeader(String name) Gets the header of date type name
Cookie [] getCookies() Gets the cookies related to the request
4. Other methods
String getContextPath() Gets the Context path (i.e. site name)
String getMethod() Get the HTTP method (GET, POST)
String getProtocol() Gets the protocol used (HTTP/1.1, HTTP/1.0)
String getQueryString() Gets the parameter string of the request. However, the HTTP method must be GET
String getRequestedSessionId() Gets the Session ID of the client
String getRequestURI() Gets the requested URL, but does not include the request parameter string
String getRemoteAddr() Get the user's IP address
String getRemoteHost() Gets the user's host name
int getRemotePort() Gets the user's host port
String getRemoteUser() Gets the user's name
void etCharacterEncoding(String encoding) sets the encoding format to solve the problem of transmitting Chinese in the form
4. response object
The response object mainly transmits the results of JSP processing data back to the client.
The response object implements the javax.servlet.http.HttpServletResponse interface. Methods provided by the response object.
1. How to set the header
void addCookie(Cookie cookie) Add cookie
void addDateHeader(String name, long date) adds a long value 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 an int type value to the name header
void setDateHeader(String name, long date) Specifies a long value to the name header
void setHeader(String name, String value) Specifies a String type value to the name header
void setIntHeader(String name, int value) Specifies the value of type int to the name header
2. How to set response status code
void sendError(int sc) Send status code (status code)
void sendError(int sc, String msg) sends status code and error information
void setStatus(int sc) Set status code
3. Methods used for URL rewriting
String encodeRedirectURL(String url) encodes the URL using the sendRedirect() method
5. out object
The out object can output the results to the web page.
out is mainly used to control and manage the output buffer and output stream.
void clear() clears the contents of the output buffer
void clearBuffer() clears the contents of the output buffer
void close() closes the output stream and clears all contents
int getBufferSize() Gets the current buffer size (KB)
int getRemaining() Gets the remaining buffer size (KB) after current use
boolean isAutoFlush() returns true to indicate that the buffer will be automatically cleared when it is full; false to indicate that it will not be automatically cleared and an exception will be generated.
6. session object
The session object represents the current session status of an individual user.
The session object implements the javax.servlet.http.HttpSession interface and the methods provided by the HttpSession interface.
long getCreationTime() Gets the time when the session is generated, in milliseconds
String getId() gets the ID of the session
long getLastAccessedTime() Gets the time when the user last sent a request through this session
long getMaxInactiveInterval() obtains the maximum session inactivity time. If this time is exceeded, the session will expire.
void invalidate() cancels the session object and completely discards the contents stored in the object
boolean isNew() determines whether the session is "new"
void setMaxInactiveInterval(int interval) sets the maximum session inactivity time. If this time is exceeded, the session will become invalid.
7. Application object
The application object is most commonly used to access information about the environment.
Because environment information is usually stored in the ServletContext, the application object is often used to access the information in the ServletContext.
The application object implements the javax.servlet.ServletContext interface, and the methods provided by the ServletContext interface container
int getMajorVersion() Gets the main Servlet API version of Container
int getMinorVersion() Gets the minor Servlet API version of Container
String getServerInfo() Get the name and version of the Container
String getMimeType(String file) Gets the MIME type of the specified file
ServletContext getContext(String uripath) Gets the Application context of the specified Local URL
String getRealPath(String path) Gets the absolute path of the local path
void log(String message) writes information to the log file
void log(String message, Throwable throwable) writes the exception information generated by stack trace into the log file
8. pageContext object
The pageContext object can access other implicit objects.
1. The pageContext object's method of accessing other implicit object attributes requires specifying a range of parameters.
Object getAttribute(String name, int scope)
Enumeration getAttributeNamesInScope(int scope)
void removeAttribute(String name, int scope)
void setAttribute(String name, Object value, int scope)
There are four range parameters, representing four ranges: PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, APPLICATION_SCOPE
2. Methods for the PageContext object to obtain other implicit objects
Exception getException() returns the exception of the current web page, but this web page must be an error page.
JspWriter getOut() returns the output stream of the current web page, for example: out
Object getPage() returns the Servlet entity (instance) of the current web page, for example: page
ServletRequest getRequest() returns the request of the current web page, for example: request
ServletResponse getResponse() returns the response of the current web page, for example: response
ServletConfig getServletConfig() returns the ServletConfig object of the current web page, for example: config
ServletContext getServletContext() returns the current execution environment (context) of this web page, for example: application
HttpSession getSession() returns the session related to the current web page, for example: session
3.PageContext object provides methods to obtain attributes
Object getAttribute(String name, int scope) returns the name attribute, the scope is the attribute object of scope, and the return type is Object
Enumeration getAttributeNamesInScope(int scope) Returns the attribute names of all attributes in scope, and the return type is Enumeration
int getAttributesScope(String name) returns the attribute scope whose attribute name is name
void removeAttribute(String name) Removes the attribute object whose attribute name is name
void removeAttribute(String name, int scope) Removes the attribute object whose attribute name is name and scope is scope
void setAttribute(String name, Object value, int scope) specifies the name of the attribute object as name, the value as value, and the scope as scope
Object findAttribute(String name) Finds the attribute object whose attribute name is name in all scopes
9. exception object
To use the exception object, it must be set in the page directive. <%@ page isErrorPage="true" %> can be used.
Three methods provided by exception:
getMessage( )
getLocalizedMessage( ),
printStackTrace(new java.io.PrintWriter(out))