One, Page object
The Page object represents the JSP itself, and more accurately it represents the JSP's translated servlet, which can invoke methods defined by the Servlet class.
Second, config object
The Config object contains some of the initial data structures of the servlet.
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 ()
Iii. Request Object
The Request object contains all the requested information, such as the source of the request, the header, the cookie, the parameter values associated with the request, and so on.
The request object implements the Javax.servlet.http.HttpServletRequest interface, and the method provided can be divided into four categories:
1. Methods for storing and acquiring attributes;
void SetAttribute (String name, Object value) sets the value of the Name property to
Enumeration Getattributenamesinscope (int scope) Gets the properties of all scope scopes
Object getattribute (String name) Gets the value of the Name property
void RemoveAttribute (String name) removes the value of the Name property
2. Methods for obtaining Request parameters
String GetParameter (string name) gets the parameter value of name
Enumeration Getparameternames () get all the parameter names
string [] getparametervalues (string name) gets the parameter value for all name
Map Getparametermap () get a map of the required parameters
3. The ability to obtain the request HTTP header method
String GetHeader (string name) gets the header of name
Enumeration Getheadernames () gets all the header names
Enumeration Getheaders (String name) Gets the header of all name
int Getintheader (String name) gets the integer type name of the header
Long Getdateheader (String name) gets the date type name of the header
Cookie [] getcookies () obtain the cookies related to the request
4. Other methods
String Getcontextpath () Gets the context path (that is, the platform name)
String GetMethod () method for getting HTTP (get, POST)
String Getprotocol () Gets the protocol used (http/1.1, http/1.0)
String getquerystring () Gets the requested argument string, but the HTTP method must be a get
String Getrequestedsessionid () Gets the session ID of the client
String Getrequesturi () Gets the requested URL, but does not include the requested argument string
String getremoteaddr () Gets the IP address of the user
String Getremotehost () gets the host name of the user
int Getremoteport () Gets the user's host port
String Getremoteuser () Gets the name of the user
void etcharacterencoding (String encoding) to set the encoding format to resolve problems with the form passing Chinese
Iv. Response Objects
The response object mainly passes the results of the JSP processing data back to the client.
The response object is the implementation of the Javax.servlet.http.HttpServletResponse interface. The method provided by the response object.
1. How to set the table header
void Addcookie (Cookie cookie) New cookie
void Adddateheader (String name, long date) adds a Long value to the name header
void AddHeader (string name, String value) new string value to name header
void Addintheader (String name, int value) adds a value of type int to the name header
void Setdateheader (String name, long date) specifies the value of a long type to the name header
void SetHeader (string name, string value) specifies the value of string type to the name header
void Setintheader (String name, int value) Specifies the value of type int to the name header
2. How to set the response status code
void Senderror (int sc) Transfer status code
void Senderror (int sc, String msg) transmits status codes and error messages
void SetStatus (int sc) Set status code
3. Methods for URL rewriting (rewriting)
String encoderedirecturl (string url) encodes the URL using the Sendredirect () method
Five, out object
The Out object can output the results to a Web page.
Out is primarily used to control the output stream (buffer) of the management outputs.
void Clear () clears the contents of the output buffer
void Clearbuffer () clears the contents of the output buffer
void Close () closes the output stream, clearing all content
int getbuffersize () gets the current buffer size (KB)
int getremaining () gets the buffer size remaining after the current use (KB)
A Boolean Isautoflush () return True indicates that the buffer is automatically cleared when full; false means that it is not automatically cleared and exception handling is generated
Vi. Session Object
The Session object represents the current status of the sessions of individual users.
The session object implements the Javax.servlet.http.HttpSession interface, and the method provided by the HttpSession interface
Long GetCreationTime () Gets the time that the session was generated, in milliseconds
String getId () Gets the ID of the session
Long Getlastaccessedtime () Gets the time at which the user finally sent the request through this session
Long Getmaxinactiveinterval () gets the maximum session inactivity time, if more than this time, the session will be invalidated
void invalidate () cancels the session object and discards the contents of the object
Boolean isnew () determines whether the session is a "new"
void setmaxinactiveinterval (int interval) sets the maximum time that the session will not be active, and if this time is exceeded, the session is invalidated
Vii. Objects of Application
Application objects are most commonly used in accessing information in the environment.
Because the information in the environment is usually stored in ServletContext, the Application object is often used to access information in the ServletContext.
The Application object implements the Javax.servlet.ServletContext interface, and the method provided by the ServletContext interface container
int getmajorversion () gets container main servlet API version
int getminorversion () gets container minor servlet API version
String Getserverinfo () gets 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 for the specified local URL
String Getrealpath (string path) obtains the absolute path of the local side path
void log (String message) writes information to the log file
void log (String message, throwable throwable) writes the exception information generated by the stack trace to the log file
Viii. Objects of PageContext
PageContext objects can access other hidden objects.
A 1.pageContext object accesses other methods that suppress object properties, and you need to specify 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)
The range parameter has four, representing four kinds of range: Page_scope, Request_scope, Session_scope, Application_scope
2.PageContext object methods for acquiring other hidden objects
Exception GetException () callback the current page of the exception, but this page is error page,
JspWriter Getout () callbacks the current page's output stream, for example: out
Object GetPage () callbacks the servlet entity (instance) of the current Web page, for example: page
ServletRequest getrequest () to return a request for the current webpage, for example: request
Servletresponse GetResponse () callback The current Web page response, for example: response
ServletConfig Getservletconfig () callbacks the ServletConfig object currently on this page, for example: Config
ServletContext Getservletcontext () callbacks the current execution Environment (context) for this page, for example: application
HttpSession getsession () return to the current Web page (session), for example: Session
3.PageContext objects provide a way to get properties
Object GetAttribute (String name, int scope) callbacks The Name property, scoped to the Property object, and the callback type is Object
Enumeration Getattributenamesinscope (int scope) callbacks all property names with scope, and the callback type is enumeration
int Getattributesscope (String name) property range with the name of the callback property named name
void RemoveAttribute (String name) removes a Property object with the name of the property
void RemoveAttribute (String name, int scope) Remove Property object named Name, scope
void SetAttribute (String name, object value, int scope) specifies that the Property object is named Name, value is
Object Findattribute (String name) looks for Property object with name in all scopes
Ix. Exception objects
To use the exception object, you must set it in the page directive. <%@ page iserrorpage= "true"%> to use.
Exception provides three ways to:
GetMessage ()
Getlocalizedmessage (),
Printstacktrace (New Java.io.PrintWriter (out))
The nine hidden objects of a JSP